1

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

sudarshan
  • 21
  • 5

1 Answers1

0

You should debug step by step in order to find whether the function "postAdapter.notifyDataSetChanged()" is executed.

Sumit patel
  • 3,807
  • 9
  • 34
  • 61
  • If the resultCode doesn't matches ,the following code can't be executed surely. – Han.Engineer Nov 17 '16 at 09:22
  • now i have made some changes in code now everything works ok, the postAdapter.notifyDataSetChanged() also getting called but only listview does not get refreshed – sudarshan Nov 17 '16 at 11:21
  • You can try to check whether or not the class of PostListAdapter is writed correctedly. – Han.Engineer Nov 17 '16 at 13:38
  • hello after lot of search i found that the listview got notified but the data gets added on the bottom of arraylist listview. what is solution on that? can you tell me please? – sudarshan Nov 18 '16 at 06:03
  • Is it easy for you to solve this problem?Either the adapter or layout may be writed wrongly by you – Han.Engineer Nov 18 '16 at 14:59