Get the App
SLTechnology News&Howtos  ›  Development  › 

How to operate AlertDialog in Android

Shulou Source: shulou.com Published: 2022-05-31 21:46:32 10月02日 Update

This article mainly introduces the relevant knowledge of how to operate AlertDialog in Android, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will have something to gain after reading this Android article on how to operate AlertDialog. Let's take a look.

Android AlertDialog code example:

Package maximyudin.AlertDialogBuilderSample; import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.view.View; import android.app.AlertDialog; import android.content.DialogInterface; public class AlertDialogBuilderSample extends Activity {@ Override public void onCreate (Bundle icicle) {super.onCreate (icicle); setContentView (R.layout.main); final Button btnQuit = (Button) findViewById (R.id.btnQuit) BtnQuit.setOnClickListener (new Button.OnClickListener () {public void onClick (View v) {new AlertDialog.Builder (AlertDialogBuilderSample.this) .setTitle ("Question") .setMessage ("Are you sure that you want to quit?") .setIcon (R.drawable.question) .setPositiveButton ("Yes", new DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int whichButton) {setResult (RESULT_OK); finish () ) .setNegativeButton ("No", new DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int whichButton) {}) .show ();}}); final Button btnTravels = (Button) findViewById (R.id.btnTravels) BtnTravels.setOnClickListener (new Button.OnClickListener () {public void onClick (View v) {new AlertDialog.Builder (AlertDialogBuilderSample.this) .setTitle ("I want to go to") .setItems (R.array.items_indide_dialog, new DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int whichcountry) {String [] travelcountries = getResources (). GetStringArray (R.array.items_indide_dialog)) New AlertDialog.Builder (AlertDialogBuilderSample.this) .setMessage ("I'm going to" + travelcountries [whichcountry]) .setNeutralButton ("Cancel", new DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int whichButton) {}) .show ();}) .show ();}) }} this is the end of the article on "how to operate AlertDialog in Android". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to operate AlertDialog in Android". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Knowledge content articles code value easy to operate articles easy to understand more read it examples industry information information channels channels learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Shulou Information Xiaomi OPPO Reno