Skip to content

Instantly share code, notes, and snippets.

@YvesBill
Created August 16, 2013 16:11
Show Gist options
  • Select an option

  • Save YvesBill/6251242 to your computer and use it in GitHub Desktop.

Select an option

Save YvesBill/6251242 to your computer and use it in GitHub Desktop.
...
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.alert:
alert();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void alert() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
// settare il titolo
alertDialogBuilder.setTitle("Title");
alertDialogBuilder.setIcon(R.drawable.ic_launcher);
// settare il messaggio
alertDialogBuilder
.setMessage("Message")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// Intento, in questo caso apre una applicazione ma potrebbe essere una classe o altro
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.Lunar.HD"));
startActivity(myWebLink);
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// close AlertDialog
dialog.cancel();
Toast.makeText(getApplicationContext(),
"Close", Toast.LENGTH_LONG).show();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment