How to update listview when back pressed from another activity android?

前端 未结 3 1937
北海茫月
北海茫月 2021-01-18 09:48

Hi how to update listView when back pressed in another activity. I am using database, where i am deleting particular row in one Activity, if back p

相关标签:
3条回答
  • 2021-01-18 10:29

    Delete that item from the customerDetail list and then call notifydatasetchanged()

    0 讨论(0)
  • 2021-01-18 10:37

    call finish() in Activity1

    Intent intent = new Intent(getApplicationContext(), Activity2.class);
    startActivity(intent);
    finish();
    

    In Activity2 override backPressed

    public void onBackPressed(){
        Intent i = new Intent(this,AdminActivity.class);
        startActivity(i);
    }
    
    0 讨论(0)
  • 2021-01-18 10:41

    First write below method in Adapter

        public void updateList(List<Messages> mChatDetails) {
        this.mChatDetails.clear();
        this.mChatDetails.addAll(mChatDetails)
    }
    

    In resume fetch the data from database and call updateList(List mChatDetails) method then call notifyDatasetChanged()

        @Override
    public void onResume() {
        // fetch updated data
        adapter.updateList(mChatDetails);
        adapter.notifyDataSetChanged();
    }
    
    0 讨论(0)
提交回复
热议问题