嗨我想从一个类发送字符串arraylist值另一个class.i尝试使用bundle概念但在arraylist的第二个类中显示null value.plaese任何一个建议我wherre确实错了..
Activity1.class:
public static ArrayList<String> customers = new ArrayList<String>();
customers.add("radha");
customers.add("aswini");
Intent i=new Intent(Activity1 .this,Activity2.class);
i.putExtra("customers1", customers);
Log.i("arrayvalues1",""+ customers);
startActivity(i);
Activity2.class:
String[] mystringArray = getIntent().getStringArrayExtra("customers1");
Log.i("arrayvalues2",""+ mystringArray);
答案 0 :(得分:2)
ArrayList<String> mystringArray = getintent().getStringArrayListExtra("customers1");
答案 1 :(得分:0)
当arraylist是public static时,你可以使用classname.arraylist na直接访问它。
Activity1.cutomers
答案 2 :(得分:0)
如果您创建公共静态变量,则可以以静态方式访问它:
在Activity2.class中:
Activity1.customers;
答案 3 :(得分:0)
活动1:
ArrayList<String> Customers = new ArrayList<String>();
Intent i=new Intent(Activity1 .this,Activity2.class);
i.putStringArrayListExtra("customers1",(ArrayList<String>) Customers);
startActivity(i);
活动2:
ArrayList<String> Customers = new ArrayList<String>();
Bundle extra=getIntent().getExtras();
if(extra!=null){
Customers =extra.getStringArrayList("customers1");
}