1

It may be easier for those who are familiar with android code. I'am newbie here... I just working on to do an action after my snackbar dismissed. I read tutorial here but still not give me clear direction.

    adapterTutorSubject.setOnClickListener(new AdapterTutorSubject.OnClickListener() {
        @Override
        public void onItemClick(View view, TutorSubject obj, int pos) {
            Snackbar.make(parent_view, "Item " + obj.subjectName + " clicked", Snackbar.LENGTH_SHORT).show();


         //On snackbar dismissed, then go to this page

            Intent intent = new Intent(getApplicationContext(), ChapterListActivity.class);
            startActivity(intent);
        }
    });

Thanks!

Nere
  • 4,097
  • 5
  • 31
  • 71
  • After question submitted, I finally found the solution... sometimes I need to ask in SO then I found it..hahahah https://stackoverflow.com/questions/30926380/how-can-i-be-notified-when-a-snackbar-has-dismissed-itself – Nere Jan 12 '18 at 20:52

1 Answers1

2

You could simply setCallback as shown here. Modify the code like:

adapterTutorSubject.setOnClickListener(new AdapterTutorSubject.OnClickListener() {
        @Override
        public void onItemClick(View view, TutorSubject obj, int pos) {
            Snackbar snack = Snackbar.make(parent_view, "Item " + obj.subjectName + " clicked", Snackbar.LENGTH_SHORT);
            snack.setCallback(new Snackbar.Callback() {

                    @Override
                    public void onDismissed(Snackbar snackbar, int event) {
                       if (event == Snackbar.Callback.DISMISS_EVENT_TIMEOUT) {
                         // Snackbar closed on its own
                       }
                    }

                    @Override
                    public void onShown(Snackbar snackbar) {
                       //Do something in shown
                    }
           });
           snack.show();
        }
    });

Hope it helps!!!

Kostas Drak
  • 3,222
  • 6
  • 28
  • 60