Baseadapter can be the most flexible to implement the ListView, the inside of the control can also get focus, allow the Click. Examples are as follows:
Main.xml
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" ><ListViewAndroid:id= "@+id/mylist"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"/></LinearLayout>
Main method:
Public classBaseadaptertestextendsactivity{ListView myList; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); MyList=(ListView) Findviewbyid (r.id.mylist); Baseadapter Adapter=NewBaseadapter () {@Override Public intGetCount () {//specify a total of 40 options return40; } @Override PublicObject GetItem (intposition) { return NULL; } //override this method, and the return value of the method will be the ID of the list item@Override Public LongGetitemid (intposition) { returnposition; } //override this method, and the view returned by the method will be used as a list box@Override PublicView GetView (intposition, View Convertview, ViewGroup parent) { //Create a LinearLayout and add 2 components to itLinearLayout line =NewLinearLayout (baseadaptertest. This); Line.setorientation (0); ImageView Image=NewImageView (baseadaptertest. This); Image.setimageresource (R.drawable.ic_launcher); TextView text=NewTextView (baseadaptertest. This); Text.settext ("First" + (position +1) + "list items"); Text.settextsize (20); Text.settextcolor (color.red); Line.addview (image); Line.addview (text); //Returning LinearLayout instances returnLine ; } }; Mylist.setadapter (adapter); }}
The effect is as follows:
The Baseadapter of Android development