I have an Activity which I start like this:
public class MyProblemsActivity extends ListActivity
{
String[] PROBLEMS = new String[] {"One", "Two", "Three" };
ArrayAdapter adapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
adapter = new ArrayAdapter<String>(this,R.layout.my_problems, PROBLEMS);
setListAdapter(adapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
and that works totally fine.
The problem I run into is after a call to a remote server via a Asynch call, I do this:
@Override
protected void onPostExecute(String result)
{
PROBLEMS = new String[] {"Hello", "Bye", "Hmmmmmm" };
adapter.notifyDataSetChanged();
}
But the screen does not update. What am I doing wrong here and how can I get the screen to update with the new values?
Thanks!!
what’s happening is at
the
PROBLEMSis getting the reference tonewstring array object…Thus the old reference is remaining as it is(unchanged)..to correct it, use following :
this way new string(s) will be added only to existing array reference pointed out by PROBLEMS
NOTE: i have mentioned by referencing the use of arraylist of string instead of string[] , to use clear(),addAll() functionalites of it, you can modify it for String[] as per your use..