Directory
- Array Adapter Arrayadapter
- Simple Adapter Simpleadapter
- Custom Adapter Baseadapter
Array adapter Arrayadapter
Brief introduction:
Arrayadapter is a list adapter for Android that is used to fit the control between this type of ListView and the data.
The default Arrayadapter expects the accepted style file to contain only a single TextView
How to use:
Achieve the following effects:
XML layout:
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"> <ListViewAndroid:id= "@+id/li"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"></ListView></LinearLayout>
Java code:
Package Com.contentprovide.liuliu.demo_01;import Android.support.v7.app.appcompatactivity;import Android.os.bundle;import Android.view.view;import Android.widget.adapterview;import Android.widget.ArrayAdapter; Import Android.widget.listview;import Android.widget.textview;import Android.widget.toast;public class MainActivity Extends Appcompatactivity {arrayadapter<string> arrayadapter; ListView Li; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Li = (ListView) Findviewbyid (r.id.li);arrayadapter = new Arrayadapter (mainactivity.this,r.layout.support_simple_spinner_dropdown_item);Add Content Arrayadapter.add ("1") to the array adapter; Arrayadapter.add ("2"); Arrayadapter.add ("3"); Arrayadapter.add ("4");//Add the array adapter to the ListView objectLi.setadapter (arrayadapter);Add a click event to the ListView object: Click on each textview option to eject the corresponding content on the text box Li.setonitemclicklistener (new Adapterview.onitemclicklistener () {@Override public void Onitemclick (adapterview<?> adapterview, view view, int I, long l) { TextView t = (TextView) view; String s = T.gettext (). toString (); Toast.maketext (Getapplicationcontext (), S,toast.length_short). Show (); } }); }}
Simple Adapter Simpleadapter
Custom Adapter Baseadapter
Use of the Android adapter (Arrayadapter, Simpleadapter, Baseadapter)