【问题标题】:I want to display source class array list into destination class我想将源类数组列表显示到目标类中
【发布时间】:2013-07-19 14:14:18
【问题描述】:

我想将数组列表从一个活动传递到另一个活动。我正在尝试这样: 我将数组列表源活动传递给目标活动。但问题是我在目的地活动中只得到最后一项。

我的代码是

source.class

HashMap<String,String> hm = new HashMap<String, String>();
ArrayList<HashMap<String,String>> arl = new ArrayList<HashMap<String,String>>();
hm.put(KEY_NAME,u);//am adding these values through loop
arl.add(hm);//adding Hash Map to Array List

Intent intent = new Intent(MainActivity.this, SinglePlaceActivity.class);
intent.putExtra("arraylist", arl

startActivityForResult(intent, 500);
System.out.println("uuuuu"+arl);//upto now working good and display perfectly all array list 

destination.class

ArrayList<HashMap<String, String>> arl = ArrayList<Hash 
Map<String,String>>)getIntent().getSerializableExtra("arraylist");
System.out.println(arl);//am getting what i add last item in the Arrylist at source class 

 Iterator itr = arl.iterator(); 
    while(itr.hasNext())
                      {
    System.out.println(itr.hasNext);//am getting  single last item multiple times.what i add last item in the Arrylist at source class

我想将源类数组列表显示到目标类中。

【问题讨论】:

  • 根据您提供的代码,您似乎只向 arl 添加了 1 个 iem。您在哪里添加其他项目?
  • 您能否发布一些详细代码来构建您的意图和参数?

标签: android android-intent arraylist


【解决方案1】:

尝试使用: Bundle.putSerializable() 和 Bundle.getSerializable()。

另外,在:

System.out.println(itr.hasNext);

不应该是its.next()吗?

还要考虑到在 Android IPC 中使用 Seralizable 对象会增加关于使用 Parcelable 对象的重大偷听。

【讨论】:

    猜你喜欢
    • 2018-08-01
    • 2022-01-02
    • 1970-01-01
    • 2010-11-29
    • 2019-05-30
    • 1970-01-01
    • 2014-11-22
    • 2018-03-22
    • 1970-01-01
    相关资源
    最近更新 更多