Refreshing Activity When Dialog Dismisses

2019-04-14 14:33发布

Actually in my list activity,when user taps on any item ,a dialog box is opened with two options of delete and cancel.When user select delete button the dialog dismisses with deleting value in database.And the old list activity comes in foreground with old values.Though it is deleted it is showing in listview.Is there a way to show the refreshed list.If yes,then How?

7条回答
别忘想泡老子
2楼-- · 2019-04-14 14:41

Try this, implement the dialog dismiss listener and check if the user has clicked on your "delete" button, if yes then perform your refresh

        dialog.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {

            }
        })

Refresh the listview by setting the apdater again....

查看更多
家丑人穷心不美
3楼-- · 2019-04-14 14:42

When closing the Dialog call

yourAdapter.notifyDataSetChanged()

on your list adapter.

查看更多
Deceive 欺骗
4楼-- · 2019-04-14 14:43

clear the list using list.clear(); and set the adapter like this adapter = new Adapter(this); enter code herelistView.setAdapter(adapter);

查看更多
孤傲高冷的网名
5楼-- · 2019-04-14 14:50

If you are using array list then you must definitely know the item position and using that position you can remove item from your list .Then call the

     yourlist.remove(position);
     adapter.notifyDataSetChanged();

run your program to watch the magic.

查看更多
爷、活的狠高调
6楼-- · 2019-04-14 14:53

Please try following code,

private final Handler handler = new Handler();

make a function called: doTheAutoRefresh() that does:

private void doTheAutoRefresh() {
    handler.postDelayed(new Runnable() {
             doRefreshingStuff(); // this is where you put your refresh code
             doTheAutoRefresh();
         }, 1000);
}

Call this function in your onCreate.

NOTE: this is the basic approach. consider stopping this after onPause has been called and to resume it after onResume. Look at the handler class to see how to remove.

查看更多
仙女界的扛把子
7楼-- · 2019-04-14 14:57

you need to remove the deleted item from adapter too before calling adapter's notifyDataSetChanged() in order to refresh your list

查看更多
登录 后发表回答