Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to operate AlertDialog in Android

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report