i have a fragment activity 'feedlistActivity' inside this i have a fragment 'myPostFragment' this fragment contains a listView, and from that fragment i called startActivityForResult to start a new activity '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);
}
My Problem is that above code does not works for me when i call 'notifyDatasetChanged' and list does not get refreshed instantly