I'm currently working on implementing ShowcaseView into an app. My goal is to change views when the done button is pressed.
But once it changes to the new view, the whole code block runs again, and the ShowcaseView pops up again on the next page. Everything works properly until I add in the code to change views. How can I solve this?
Here is the code I have so far:
public void createShowView() {
ShowcaseView sc = new ShowcaseView.Builder(getActivity())
.setTarget(new ViewTarget())
.setContentTitle("")
.setContentText("")
.setStyle(R.style.CustomShowcaseTheme2)
.hideOnTouchOutside()
.setShowcaseEventListener(new SimpleShowcaseEventListener() {
public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
Intent tab2 = new Intent(getContext(), tabs.class);
tab2.putExtra("Specific Tab", 1);
startActivity(tab2);
}
})
.build();
}
public void createDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("To view a full tutorial of ...., press continue.")
.setTitle("View Tutorial");
builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
createShowView();
}
});
builder.setNegativeButton("Skip Tutorial", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getActivity().getSharedPreferences("PREFERENCE", Context.MODE_PRIVATE).edit()
.putBoolean("isfirstrun", false)
.commit();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Boolean isFirstRun = this.getActivity().getSharedPreferences("PREFERENCE", Context.MODE_PRIVATE)
.getBoolean("isfirstrun", true);
if (isFirstRun) {
createDialog();
}
}