我有一个片段活动'feedlistActivity'在这里面我有一个片段'myPostFragment'这个片段包含一个listView,并从这个片段我调用startActivityForResult开始一个新的活动'MyActivity'。
MyActivity.class
Intent returnIntent = new Intent();
returnIntent.putExtra("POST_OBJECT", postData);
setResult(Activity.RESULT_OK, returnIntent);
finish();
MyPostFragment.class
Intent editIntent = new Intent(context, MyActivity.class);
editIntent.putExtra("EDIT_POST", postDetailsData);
startActivity(editIntent);
break;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == ADD_EDIT_POST ) {
if (data != null && data.hasExtra("POST_OBJECT")) {
PostDetailsData postData = (PostDetailsData) data
.getSerializableExtra("POST_OBJECT");
if (postData != null) {
myPostFeedList.add(postData);
postAdapter.notifyDataSetChanged();
setAdapter();
}
}
}
}
private void setAdapter() {
// if (postAdapter == null) {
postAdapter = new PostListAdapter(context, myPostFeedList);
postAdapter.setSwipeOptionClickedListner(this);
myPostfeedListView.setAdapter(postAdapter);
postAdapter.notifyDataSetChanged();
// } else {
// postAdapter.notifyDataSetChanged();
// }
}
FeedlistActivity.class
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
我的问题是,上面的代码不适合我,当我调用'notifyDatasetChanged'和列表不得到刷新立即
您应该逐步调试,以确定函数 "postAdapter.notifyDataSetChanged()"
是否被执行。