Reputation: 195
I have the following code:
if(isSolved()){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("You solved the puzzle! Congratulations!")
.setCancelable(false)
.setPositiveButton("Thanks.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent(context, MainMenuActivity.class);
startActivity (intent);
}
});
}
It's a puzzle and when the puzzle it resolved it shows the above message:"Congrats! you finished the game!". But when I press ok it doesn't do anything. I would want after pressing ok to redirect to another page. i'm using java with eclipse.
Upvotes: 1
Views: 956
Reputation: 2098
You can use alert.setButton("Okay", listener);
And in your listener catch the click event.
Upvotes: 0
Reputation: 191
You need to add OnClickListener to the PositiveButton and handle your redirect in onclick:
builder.setPositiveButton("Thanks.", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//Do your redirect here
}
});
Upvotes: 1
Reputation: 20346
builder.setMessage("Congrats! you finished the game!")
.setCancelable(false)
.setPositiveButton("Thanks.", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do something
}
});
AlertDialog.Builder.setPositiveButton()
Upvotes: 0