Sunday, January 29, 2012

Android: Updating values when returning from another activity

The problem that I had was that when returning from an activity the list was not getting update until a keyEvent was realized.

For example, the main activity contain a list of strings that gets from a database, It is updated by using the action FillData(), and I had an activity for add new elements to the database, and another for modify or delete.

The problem was that when creating/adding/modifying the values at one of the other activities and finishing this activies (returning to the main activity) the list was not updated with the new values.

The solution of this problem is to Overrite the onResume() event, looking at the graph of http://developer.android.com/reference/android/app/Activity.html that when the event is Paused, later on is called the onResume event.

For example in my case:

@Override
public void onResume(){
      super.onResume();
      EditText searchTextField=(EditText) findViewById(R.id.searchTextField);
      fillData(searchTextField.getText());
}

I get the value from an EditText field getting the filter to use when filling the list and later call to fillData that fullfills the list.

No comments:

Post a Comment