Sending ArrayList Objects between activitys
I am having a problem in trying to pass a ArrayList Object from Activity to Activity. Currently I am parsing a XML response using SAX Parser. The information I parse goes into a ArrayList. The information from the ArrayList is then used to populate a ListView using title as the name displayed on the listview slides.
What I want to be able to do is when I click on a item in the listview the assosiated information from that object will also be sent to the new activity and populate the fields which will display extra information.
I have tried creating a new adapter which links to the new XML layouts file but none 开发者_JAVA技巧of the data gets sent across. :(
I have looked into bundles but will that sent the whole arraylist or just the data that is associated with the listview I am using?
Any advice on approach's I can use to do this?
Thanks in advance
When sending from From the activity
Intent myIntent = new Intent(From.this, To.class);
myIntent.putStringArrayListExtra("name",value);
From.this.startActivity(myIntent);
and when receiving from To Activity
Bundle bundle = getIntent().getExtras();
ArrayList<String> list=bundle.getStringArrayList("name");
U can send whole of ArrayList if it holds String values using this method putStringArrayListExtra(name,value);
this has to be put into an Intent or bundle before starting the Activity using the Same intent...
You can try using the Extra Content of the Intents as shown in this thread: How do I pass data between Activities in Android application?
Also, you could inherit from the Application class and set some variables there to pass data along all the activities in your application.
精彩评论