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 use code to analyze lists, singles, and multiple selections in Dialog

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

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to use code to analyze the list, single selection, and multi-selection in Dialog. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

XML layout

Java code

Public class MainActivity extends Activity {

Private String [] items = new String [] {"Mr. Li", "Mr. Wang", "Mr. Cheng"}

Private boolean [] checked = new boolean [] {true,false,true}

@ Override

Protected void onCreate (Bundle savedInstanceState) {

Super.onCreate (savedInstanceState)

SetContentView (R.layout.activity_main)

}

Public void click (View v) {

/ / create a container

AlertDialog.Builder builder = new Builder (MainActivity.this)

/ * *

* list

, /

/ * builder.setItems (items, new OnClickListener () {

@ Override

Public void onClick (DialogInterface dialog, int which) {

Toast.makeText (getApplicationContext (), items [which], 1000) .show ()

}

}); * /

/ * *

* single selection

, /

Builder.setSingleChoiceItems (items, 2, new OnClickListener () {

@ Override

Public void onClick (DialogInterface dialog, int which) {

Toast.makeText (getApplicationContext (), items [which], 2000) .show ()

Dialog.dismiss ()

}

});

/ * *

* multiple selection

, /

/ * builder.setMultiChoiceItems (items, checked, new OnMultiChoiceClickListener () {

@ Override

Public void onClick (DialogInterface dialog, int which, boolean isChecked) {

Toast.makeText (getApplicationContext (), items [which], 2000) .show ()

Dialog.dismiss ()

}

}); * /

/ / create a Dialog

AlertDialog dialog = builder.create ()

/ / display dialog box

Dialog.show ()

}

}

After reading the above, do you have any further understanding of how to use code to analyze lists, singles, and multiple selections in Dialog? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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