Refreshing activity when dialogue is rejected
In fact, in my activity list, when the user clicks on any item, a dialog opens with two options for delete and cancel. When the user selects the delete button, the dialog is dismissed and the value in the database is deleted. And the old foreground table with old values is active. Although removed, it appears in the list. Is there any way to show the updated list. If so, how?
If you are using a list of arrays, you should definitely know the position of the position and use that position, which you can remove from your list. Then call
yourlist.remove(position);
adapter.notifyDataSetChanged();
run your program to watch the magic.
you need to remove the removed item from the adapter before calling the adapter notifyDataSetChanged () to update the list
Please try the following code,
private final Handler handler = new Handler();
create a function: doTheAutoRefresh () that does:
private void doTheAutoRefresh() {
handler.postDelayed(new Runnable() {
doRefreshingStuff(); // this is where you put your refresh code
doTheAutoRefresh();
}, 1000);
}
Calling this function in onCreate.
NOTE: this is a basic approach. consider stopping this after onPause has been called and resume after onResume. Take a look at the handler class to see how to remove it.
Try this, implement a dialog reject manager and check if the user clicked the delete button, if yes then update
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
}
})
Refresh the list view by installing apdater again ....
On closing the Dialog call
yourAdapter.notifyDataSetChanged()
on your list.
clear the list using list.clear (); and install the adapter so adapter = new adapter (this);
enter code here
listView.setAdapter (adapter)
You can override the activity method onWindowFocusChanged(boolean hasFocus)
and track the state of your activity.
Usually, if some kind of warning is displayed above your activity, the activity does not receive events onPause()
and onResume()
. But it loses focus on the displayed alert dialog and gets it when it is dismissed.
In your case, you can update your details in onWindowFocusChanged()
, if hasFocus
any true
.