Friday, 15 January 2010

android - ArrayList gets clear after coming back from another activity -


This is strange because yesterday the code was working but not today. I'm pretty sure I did not change anything.

This is the thing that I have a blank array list for the first time, then I call another activity which will be a string for the previous activity that I add to the album.

The problem is that every time I start that new activity and it gives a new string, then my Aralist is empty, so I only see the last returned string. On my ListView

I tried something about SavaveInstanceState, but it did not help. any idea? Thank you. Array List & lt; String & gt; Rule = New Arreelist & lt; String & gt; (); @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.activity_add_filters); MyList = (ListView) findViewById (R.id.listFilters); Adapter = new array adapter & lt; String & gt; (This, android.R.layout.simple_list_item_1, rule); MyList.setAdapter (adapter); } @ Override Secure Void Activity Result (The result of int RequestCode, Int code, Intent data) {if (Requestcode == REQUEST_CODE_0 and Result Code == RESULT_OK} {string aux = data.getExtras () GetString (SRULE); Rules.add (aux); // Here rules.size () is always the 1 adapter.notifyDataSetChanged (); }}

Edit: I call other code with this code in a simple way

  intent I = new intent (this, activityAdru . category); StartActivityForResult (i, S.REQUEST_CODE_0);   

I return data from that other way in another way:

  intent = new intent (); String rule = some over operation (); I.putextra (SURULE, Rules); SetResult (RESULT_OK, i);    

your code looks ok Make sure setResult (RESULT_OK, i) is always called when another activity begins.

No comments:

Post a Comment