androidshowcaseview

Fancy Show Case View


i want to make show case view in my apps, in first showcase page i want to show confirmation page that have two button ok or not, if ok then continue to next show case, if not will remove / hide showcase. but my ok button doesn't work right now, here is my code :

 // -------- First Show case ---------
 private void ShowCaseIntro(){
 mFancyShowCaseView = new FancyShowCaseView.Builder(this)
         .delay(1000)
         .customView(R.layout.tutorial, new OnViewInflateListener() {
             @Override
             public void onViewInflated(@NonNull View view) {

                 view.findViewById(R.id.btnNo).setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
                         mFancyShowCaseView.removeView();
                     }
                 });
                 view.findViewById(R.id.btnOK).setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
                         ShowCaseEditProfile();
                     }
                 });
             }
         }).closeOnTouch(false)
         .build();
 mFancyShowCaseView.show();
}

     // -------- Second Show case ---------
private void ShowCaseEditProfile (){
    mFancyShowCaseView = new FancyShowCaseView.Builder(this)
            .focusOn(imgEdit)
            .focusCircleRadiusFactor(2)
            .customView(R.layout.edit_tutorial, new OnViewInflateListener() {
                @Override
                public void onViewInflated(@NonNull View view) {
                    view.findViewById(R.id.btnOK).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            mFancyShowCaseView.hide();
                        }
                    });
                }
            }).closeOnTouch(false)
            .build();
    mFancyShowCaseView.show();

}

here is where i call method ShowCaseIntro() :

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.activity_main);
    setDefaultToolbar(false);
    ShowCaseIntro();

}

Here is button xml file :

 <Button
            android:id="@+id/btnNo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="5dp"
            android:text="Tidak"
            android:textAllCaps="false"
            android:textColor="@color/colorPrimary" />

        <Button
            android:id="@+id/btnOK"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toEndOf="@+id/btnNo"
            android:backgroundTint="@color/orange"
            android:text="OK !"
            android:textAllCaps="false"
            android:textColor="@color/white" />

Solution

  • when you are calling ShowCaseEditProfile() your mFancyShowCaseView is already attached so before calling ShowCaseEditProfile() call mFancyShowCaseView.removeView();

    private void ShowCaseIntro(){
        mFancyShowCaseView = new FancyShowCaseView.Builder(this)
                .delay(1000)
                .customView(R.layout.tutorial, new OnViewInflateListener() {
                    @Override
                    public void onViewInflated(@NonNull View view) {
    
                        view.findViewById(R.id.btnNo).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                mFancyShowCaseView.removeView();
                            }
                        });
                        view.findViewById(R.id.btnOK).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                //add this line
                                mFancyShowCaseView.removeView();
                                ShowCaseEditProfile();
                            }
                        });
                    }
                }).closeOnTouch(false)
                .build();
        mFancyShowCaseView.show();
    }