Arrayadapter:
Arrayadapter<string> (context context, int resource, int textviewresourceid, string[] objects)
Parameters:
1.context: Context
2.resource: Layout file
3.TEXTVIEWRESOURCEID: Resource ID of the data textview to be displayed
4.objects: The data to be displayed can only be a string
Use of the arrayadapter of the ListView
Code:
1 Importandroid.app.Activity;2 ImportAndroid.os.Bundle;3 ImportAndroid.widget.ArrayAdapter;4 ImportAndroid.widget.ListView;5 6 Public classMainactivityextendsActivity {7 8 PrivateListView LV;9 Ten @Override One protected voidonCreate (Bundle savedinstancestate) { A Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); - theString[] Objects =Newstring[]{ -"Xiao Zhi", "Xiao Zhi's wife", "Meng Meng", "Xiao Zhi's son" - }; - +lv=(ListView) Findviewbyid (r.id.lv); -Lv.setadapter (NewArrayadapter<> ( This, R.layout.item_view, R.id.lv_name, objects)); + } A at}
Item_view Layout file:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Wrap_content"5 android:orientation= "Horizontal" >6 7 <ImageView8 Android:id= "@+id/lv_phono"9 Android:layout_width= "60DP"Ten Android:layout_height= "60DP" One android:src= "@drawable/img01" /> A - <TextView - Android:id= "@+id/lv_name" the Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - android:layout_gravity= "Center_vertical" - Android:text= "First Name" + android:textsize= "20SP" /> - + </LinearLayout>
Activity_main Layout file:
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context=". Mainactivity " >6 7 <ListView8 Android:id= "@+id/lv"9 Android:layout_width= "Match_parent"Ten Android:layout_height= "Match_parent" > One </ListView> A - </Relativelayout>
The use of Android development Listview-arrayadapter