How to save an open diner after an action call

I use a snack bar to notify users of my application that they are not connected to the Internet. I added the try again action to the diner that re-checks the connection. I want the snack bar to remain displayed until I let it go (when an Internet connection is detected), but I can't get it to work. Whenever I click on an action, the diner leaves.

I set the duration for an indefinite period, and the diner remains open for an indefinite period, but it rejects when I click on the action.

I read online that disabling bookmarks automatically after clicking on an action was not always the default behavior.

change

I feel that my question may be poorly worded. I have a snack bar with an action, but I do not want the snack to be closed when the action is completed and it automatically does atm.

+7
android dismiss snackbar
source share
1 answer

You can override the OnClickListener set for the button. First make a diner and set the action using some dummy listener

Snackbar snackbar = Snackbar.make(view,"TXT",Snackbar.LENGTH_LONG).setAction("OK", new View.OnClickListener() { @Override public void onClick(View v) { } }); 

And then find the button and set your list

 snackbar.show(); ViewGroup group = (ViewGroup) snackbar.getView(); for(int i=0; i< group.getChildCount();i++){ View v = group.getChildAt(i); if(v instanceof Button){ v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { YOUR_ACTION(); } }); } } 
+1
source share

All Articles