The ListView is a very high-utilization view of the actual development, and the general system comes with an adapter that does not meet the needs of the development, which requires the developer to customize the adapter so that the ListView has a good display effect.
There is a demo that implements a mixed list of picture text.
Package Com.example.work;import Java.util.arraylist;import java.util.hashmap;import java.util.list;import android. R.integer;import android.os.bundle;import android.app.activity;import Android.view.menu;import Android.view.View; Import Android.widget.adapterview;import Android.widget.toast;import Android.widget.adapterview.onitemclicklistener;import Android.widget.listview;public class MainActivity extends Activity {private ListView listview; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); ListView = (ListView) Findviewbyid (R.id.id_list); This sets three list items, each corresponding to a picture and the corresponding text//picture array int image[] = new int[]{r.drawable.tou1,r.drawable.tou3,r.drawable.he}; Text array String text[] = {"Watch again", "Bucket Landlord", "Love Elimination"}; list Custom Adapters:
Package Com.example.work;import Java.util.arraylist;import Java.util.hashmap;import java.util.list;import Java.util.map;import Android.content.context;import Android.view.layoutinflater;import Android.view.View;import Android.view.viewgroup;import Android.widget.baseadapter;import Android.widget.imageview;import Android.widget.textview;public class Myadapter extends baseadapter{private context context;//context private int re sourceid;//the layout file of a list item private listMain activity Layout file:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " tools:context= ". Mainactivity "> <listview android:layout_width=" match_parent " android:layout_height=" Match_ Parent " android:id=" @+id/id_list " ></ListView></LinearLayout>
List item Layout:
<?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:o rientation= "Horizontal" > <imageview android:layout_width= "50DP" android:layout_height= "50DP " Android:id= "@+id/id_image" /> <textview android:layout_width= "Match_parent" android: layout_height= "Wrap_content" android:id= "@+id/id_textview" android:gravity= "center_vertical " Android:textstyle= "Bold|italic" /></linearlayout>
:
This article turns from: Android Development _ Talking about ListView (custom adapter)
Go Android's Custom adapter