Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use code to analyze lists, singles, and multiple selections in Dialog

Shulou Source: shulou.com Published: 2022-06-02 03:01:24 09月22日 Update

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.

Tags: Code content analysis teachers containers dialog boxes layout more teacher Wang knowledge articles industry information information channels channels Wang Lao Jinyi dialogue support related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology Apple NVidia macOS