The ListView inside the Andriod is a control that displays the list data, the adapter simpleadapter is bound, and the binding code is as follows:
This . Findviewbyid (R.id.listview1); Simpleadapter Adapter=new simpleadapter (context, data, resource, from, to); Lstview.setadapter ( adapter);
Click event response for an element in the ListView list:
New Onitemclicklistener () { @Overridepublicvoid Onitemclick (adapterview<?> intlong arg3) { // TODO auto-generated method Stub }};listview.setonitemclicklistener (mitemclicklistener);
For button controls such as ImageButton to implement single events, let's look at how to implement such a feature:
Inherit Simpleadapter to override GetView method
Why not inherit the Baseadapter adapter for processing because Baseadapter is a very basic base class, and for generic textviwe, the Imageview,button control's data binding is not implemented
Java code:
Private classMysimpleadapterextendsSimpleadapter {@Override PublicView GetView (intposition, View Convertview, ViewGroup parent) { //TODO auto-generated Method StubView v =Super. GetView (position, convertview, parent); ImageButton btn=(ImageButton) V.findviewbyid (R.id.icon); Btn.settag (position); Btn.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method StubMdatalist.remove ((int) V.gettag ()); Notifydatasetchanged (); Toast.maketext (Getapplicationcontext (), "Μ¥»÷îòáë" +v.gettag (), 1). Show (); } }); returnv; } PublicMysimpleadapter (Context context, List<?extendsmap<string,?>> data,intresource, string[] from,int[] to) { Super(context, data, resource, from, to); //TODO auto-generated Constructor stub } }
When you click a button, the button event needs to know which item of the ListView is clicked, and you can add a tag for each button object, where we use the index of the ListView item position as the tag
Add button response event in Android Simpleadapter, GetView Override