我在GroupListActivity中有一个listview,我想在SearchActivity上添加一些组。我在GroupListActivity()上启动了startActivityForResult,在按下SearchActivity上的后退按钮后,我得到了结果。但onActivitySesult调用notitfySetChanged()并且GroupListActivity内的列表不刷新。这是我的代码:
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();
}
}
}
}
答案 0 :(得分:-1)
我认为您的适配器中没有更改数据集。
致电
dataAdapter = new DataAdapter(context, DataList);
dataAdapter.notifyDataSetChanged();