You can use the AlertDialog. Builder. setItems method to display a String array as a list in the dialog box. The Code is as follows:
String provinces [] = "Liaoning Province", "Shandong Province", "Hebei Province", "Fujian Province", "Guangdong Province", "Heilongjiang Province", "Zhejiang Province", "Jilin Province" AlertDialog. builder builder = AlertDialog. builder (builder. setTitle ("select Province" builder. setItems (provinces, onClick (DialogInterface dialog, builder. setMessage ("You selected:" + which + ":" + builder. create (). show ();
The effect is as follows:
Using the AlertDialog. Builder. setSingleChoiceItems method, you can not only display the list in the dialog box, but also display the Option Button after the list item. Code:
String provinces [] = String [] {"Liaoning Province", "Shandong Province", "Hebei Province", "Fujian Province", "Guangdong Province", "Heilongjiang Province", "Zhejiang Province ", "Jilin Province" AlertDialog. builder builder = AlertDialog. builder (builder. setTitle ("select Province" builder. setSingleChoiceItems (provinces,-1, onClick (DialogInterface dialog, builder. setMessage ("you have selected:" + which + ":" + builder. setPositiveButton ("off", onClick (DialogInterface dialog, builder. create (). show ();
As follows: