我有一个片段活动' 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);
}
我的问题是,当我打电话给#dat; notifyDatasetChanged'时,上述代码对我不起作用。并且列表不会立即刷新
答案 0 :(得分:0)
您应该逐步调试,以查找是否执行了 "postAdapter.notifyDataSetChanged()"
功能。