Use ArrayAdapter for android (12) and androidadapter
ArrayAdapter, simpleAdapter, SimpleCursorAdapter, and BaseAdapter are commonly used.
1. ArrayAdapter is usually used to wrap multiple values of an array or List set into multiple List items.
Arrayadapter layout file:
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/lv_arrayadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView></LinearLayout></span>
ArrayAdapterTest file:
<Span style = "font-size: 18px;"> public class ArrayAdapterTest extends Activity {private ListView lv_arrayadapter; private String [] str_name = new String [] {"jack ", "debb", "robin", "kikt", "dog", "cat", "elep"}; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. arrayadapter); initView (); setData ();} private void initView () {lv_arrayada Pter = (ListView) findViewById (R. id. lv_arrayadapter); // register the listener event lv_arrayadapter.setOnItemClickListener (new OnItemClickListener () {@ Overridepublic void onItemClick (AdapterView <?> Parent, View view, int position, long id) {Toast. makeText (ArrayAdapterTest. this, str_name [position], Toast. LENGTH_SHORT ). show () ;}}) ;}private void setData () {// create ArrayAdapterArrayAdapter <String> arrayAdapter = new ArrayAdapter <String> (ArrayAdapterTest. this, android. r. layout. simple_list_item_1, str_name); // bind the adapter lv_arrayadapter.setAdapter (arrayAdapter) ;}</span>
The three parameters specified during ArrayAdapter creation are described as follows:
Contex: Context of the entire application.
TextViewResourceId: Resource ID, representing a TextView, used as the list component of ArrayAdapter.
Objects: data in the list item
Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/42353249 sentiment control _