Answer the question
In order to leave comments, you need to log in
Switch to activate after AlertDialog?
Hello, could you please help me combine the two codes. The fact is that when you click on the button, an AlertDialog pops up, and immediately, literally in a second, there is a transition to the activity. How to make it so that after clicking on the "Go" button in the AlertDialog, a transition to another activity occurs. Here is the code
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnlvl:
Intent intent = new Intent(this, ActivityOne.class);
startActivity(intent);
// TODO Call second activity
break;
default:
break;
}
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityLvl.this);
builder.setTitle("Внимание!")
.setMessage("Вы действительно хотите перейти на другое активити?")
.setIcon(R.drawable.phiz)
.setCancelable(false)
.setNegativeButton("Перейти",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
Answer the question
In order to leave comments, you need to log in
Tabs are a problem on the toaster, so keep it like this:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnlvl:
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityLvl.this);
builder.setTitle("Внимание!")
.setMessage("Вы действительно хотите перейти на другое активити?")
.setIcon(R.drawable.phiz)
.setCancelable(false)
.setPositiveButton("Перейти",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Intent intent = new Intent(this, ActivityOne.class);
startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();
// TODO Call second activity
break;
default:
break;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question