如何从一个活动到另一个活动存储和检索ArrayList [英] how to store and retrieve ArrayList from one activity to another activity

查看:71
本文介绍了如何从一个活动到另一个活动存储和检索ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sales_info);
        
         ed_unitprice=(EditText)findViewById(R.id.ed_unitprice);
		 dt_orderdate=(DatePicker)findViewById(R.id.dt_orderdate);
		 Spin_prdct = (Spinner)findViewById(R.id.spin_prdct);
		 Spin_cust_name_sales=(Spinner)findViewById(R.id.Spin_cust_name_sales);
		 Spin_uom=(Spinner)findViewById(R.id.Spin_uom);
		 btn_nxt_order=(Button)findViewById(R.id.btn_nxt_order);
}


public void onClick(View  v)
	 {
		 int day = dt_orderdate.getDayOfMonth();
		 int month = dt_orderdate.getMonth();
		 int year = dt_orderdate.getYear();
		 String ans= String.valueOf(year)+String.valueOf(month)+String.valueOf(day);
		 
		 String[] prdct=Spin_prdct.getSelectedItem().toString().replace("|", ",").split(",");
		 String[] name=Spin_cust_name_sales.getSelectedItem().toString().replace("|", ",").split(",");
		 String[] uom=Spin_uom.getSelectedItem().toString().replace("|", ",").split(",");

		 //this is ArrayList(Bundle) arr4 = new ArrayList(Bundle)
                 // i donot know why its not showing this <> so i use this() in place of <> only in this question otherwise its ok in eclipse
		 ArrayList<bundle> arr4 = new ArrayList<bundle>();
			 
		 		 
		 Intent myintent=new Intent(SalesInfo.this,Orderconform.class);
		 Bundle bnd=new Bundle();
		 bnd.putSerializable("temp", arr4);
		 
		 bnd.putString("ed_unitprice", ed_unitprice.getText().toString());
		 bnd.putString("ans", ans.toString());
		 bnd.putString("Spin_prdct", prdct[0].toString());
		 bnd.putString("Spin_cust_name_sales",name[0].toString());
		 bnd.putString("Spin_uom", uom[0].toString());
		 arr4.add(bnd);
		 myintent.putExtras(bnd);
		 SalesInfo.this.startActivity(myintent);
		 }


问题1:这是将值存储在arraylist(bundle)中的正确方法吗?
Question2:如何在另一个活动中检索此arraylist(bundle)?
Question3:如何在datagridview中显示此arraylist?

注意:我是Android的新手,请非常清楚地告诉我答案.


Qestion1: Is this correct way to store value in arraylist(bundle)??
Question2: How can I retrieve this arraylist(bundle) in another activity??
Question3: How can I show this arraylist in datagridview??

Note: I am very new to android please tell me the answers very clearly please

推荐答案

将对象从一个活动传递到另一个活动的公认方法是确保它实现Parcelable.参见 [ ^ ]样例代码的答案.

/ravi
The accepted way to pass an object from one activity to another is to ensure that it implements Parcelable. See this[^] SO answer for sample code.

/ravi


这篇关于如何从一个活动到另一个活动存储和检索ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆