Effect. The specific function is to obtain a maximum of 5 values, and then construct a list for the user to select.
First, define a number value:
Int num = 5; // the specified quantity.
Then construct a String Array
String [] Nums = new string [(INT) num]; for (INT I = 0; I <nums. length; I ++) {Nums [I] = "" + (I + 1 );}
Alertdialog
Final builder B = new alertdialog. builder (mainactivity. this); B. settitle ("Select Quantity"); B. setitems (Nums, new tdilog (); B. create (). show ();
Customize a class to implement the Android. content. dialoginterface. onclicklistener Interface
Class tdilog implements android. content. dialoginterface. onclicklistener {@ override public void onclick (dialoginterface dialog, int which) {// todo auto-generated method stub int nn = which + 1; toast. maketext (getapplicationcontext (), "The number you choose is" + nn + "", toast. length_long ). show ();}}
So far, this small feature has been completed.