In a snackbar action, how can I be sure it's safe to permanently delete a soft-deleted record from the database?

后端 未结 5 1322
轻奢々
轻奢々 2021-02-04 02:29

I am using Snackbar in android and I have implemented an action so that user can undo the action (the action is clearing all the items in the listview).Removing and adding the i

5条回答
  •  南旧
    南旧 (楼主)
    2021-02-04 03:19

    Android Support library v23 added Snackbar.Callback which you can use to listen if the snackbar was dismissed by user or timeout.

    Example borrowed from astinxs post:

    Snackbar.make(getView(), "Hi there!", Snackbar.LENGTH_LONG).setCallback( new Snackbar.Callback() {
                @Override
                public void onDismissed(Snackbar snackbar, int event) {
                    switch(event) {
                        case Snackbar.Callback.DISMISS_EVENT_ACTION:
                            Toast.makeText(getActivity(), "Clicked the action", Toast.LENGTH_LONG).show();
                            break;
                        case Snackbar.Callback.DISMISS_EVENT_TIMEOUT:
                            Toast.makeText(getActivity(), "Time out", Toast.LENGTH_LONG).show();
                            break;
                    }
                }
    
                @Override
                public void onShown(Snackbar snackbar) {
                    Toast.makeText(getActivity(), "This is my annoying step-brother", Toast.LENGTH_LONG).show();
                }
            }).setAction("Go away!", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                }
            }).show();
    

提交回复
热议问题