androidandroid-recyclerviewshowcaseview

Showcaseview library calling multiple times on Recyclerview's first item


I am using https://github.com/florent37/TutoShowcase this showcaseview library in my code.

It works fine in activity and fragment.But when I call in recyclerview item it shows multiple popups and gets blackout.

mRecyclerViewList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    Logger.log("Call");

                    TextView textView = (TextView) mRecyclerViewList.getChildAt(0).findViewById(R.id.txt_add_tocart_btn);
                    Logger.log("Textview" + textView);
                    textView.setFocusableInTouchMode(true);
                    TutoShowcase.from((Activity) context).setContentView(R.layout.tuto_showcase_tuto_sample)
                            .setFitsSystemWindows(true).on(textView).addRoundRect(35).showOnce("1").show();
                    // unregister listener (this is important)
                    if (Build.VERSION.SDK_INT < 16) {
                        mRecyclerViewList.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    } else {
                        mRecyclerViewList.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    }
                }
            });

How can I avoid multiple popup's?


Solution

  • Your question how to avoid Multiple popup's:

    Just set a boolean value to avoid showing multiple times.

    boolean isShown = false;
    
    mRecyclerViewList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        Logger.log("Call");
                        if(!isShown){
                          TextView textView = (TextView) mRecyclerViewList.getChildAt(0).findViewById(R.id.txt_add_tocart_btn);
                          Logger.log("Textview" + textView);
                          textView.setFocusableInTouchMode(true);
                          TutoShowcase.from((Activity) context).setContentView(R.layout.tuto_showcase_tuto_sample)
                                .setFitsSystemWindows(true).on(textView).addRoundRect(35).showOnce("1").show();
                           isShown = true;
                         }
                        // unregister listener (this is important)
                        if (Build.VERSION.SDK_INT < 16) {
                            mRecyclerViewList.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        } else {
                            mRecyclerViewList.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                });