LinearLayout Linearlayoutmain = new LinearLayout (this);//Customize a layout file
Linearlayoutmain.setlayoutparams (New Layoutparams (
Layoutparams.match_parent, layoutparams.wrap_content));
ListView ListView = New ListView (this);//this to get the current context
Listview.setfadingedgelength (0);
list<map<string, string>> namelist = new arraylist<map<string, string>> ();// Create an array to store the data displayed on the ListView
for (int m = 0; m < initdata.size (); m++) {//initdata is a data source of list type
map<string, string> namemap = new hashmap<string, string> ();
Namemap.put ("Name", Initdata.get (M). Get (Tagitem.name). toString ());
Namelist.add (NAMEMAP);
}
Simpleadapter adapter = new Simpleadapter (Uploadphotoactivity.this,
NameList, R.layout.item_uploadphoto_select_name,
New string[] {"Name"},
New int[] {r.id.tv_uploadphoto_select_name_item});
Listview.setadapter (adapter);
Linearlayoutmain.addview (listview);//Add a ListView to this layout
Final Alertdialog Dialog = new Alertdialog.builder (this)
. Settitle ("Select Patient Name"). Setview (Linearlayoutmain)//The layout of this ListView that is written here is loaded dialog
. Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialog, int which) {
TODO auto-generated Method Stub
Dialog.cancel ();
}
}). Create ();
Dialog.setcanceledontouchoutside (false);//Make it impossible to click anywhere but dialog
Dialog.show ();
Listview.setonitemclicklistener (New Onitemclicklistener () {//Response click event for item in ListView
@Override
public void Onitemclick (adapterview<?> arg0, View arg1, int arg2,
long arg3) {
//TODO auto-g enerated method Stub
TextView TV = (TextView) arg1
. Findviewbyid (R.id.tv_uploadphoto_select_name_item);// Gets the TextView control in each item
Et_name.settext (Tv.gettext (). toString ());
Dialog.cancel ();
}
});