I have a listview in GroupListActivity and I want to add some groups on SearchActivity. I started startActivityForResult on GroupListActivity() and after I press the back button on SearchActivity I get the result. But onActivitySesult call notitfySetChanged() and the list inside GroupListActivity doesn't refresh. This is my code:
public class GroupsListActivity extends Activity {
private static final int REQUEST = 1;
String loggedUserId = Model.getInstance().getLoggedUserId();
ListView list;
List<Group> data;
MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set layout for this activity
setContentView(R.layout.groups_list);
// Show actionbar in this activity
getActionBar().show();
if(loggedUserId != null)
Log.d("TAG", "My Groups for user ID: " + loggedUserId);
// Connect between button to layout id
list = (ListView) findViewById(R.id.my_group_list);
// Setting adapter and creating group list
if(loggedUserId != null) {
Model.getInstance().getAllGroupsByUserId(loggedUserId, new Model.groupListReturnedListener() {
@Override
public void groupListReturned(List<Group> groupList) {
data = groupList;
adapter = new MyAdapter();
list.setAdapter(adapter);
Collections.sort(data, Group.Comparators.NAME); //Sort array
}
});
}
}
private void onSearch() {
Log.d("TAG", "Search button was pressed");
Intent i = new
Intent(getApplicationContext(),
SearchActivity.class);
startActivityForResult(i, REQUEST);
overridePendingTransition(R.animator.slide_out_right, R.animator.slide_in_right);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST) {
if(resultCode == RESULT_OK) {
adapter.notifyDataSetChanged();
}
}
}
}