一、效果预览图
二、思路
- 创建自定义类模型,即定义某些属性的Java对象(此处属性为图片+姓名+生日)
- 创建视图模板,即list中每一行的布局
- 创建自定义适配器,继承ArrayAdapter,改写getView()方法
- 在activity_main.xml中创建ListView
- 在ListView的activity即MainActivity中,创建ArrayList集合,将其添加到ArrayAdapter适配器中,将适配好的内容放到ListView控件中
- 将图片资源添加到res/drawable中
- 将自定义的数据内容导入ArrayList集合中
三、具体实现
- 创建自定义类模型,即定义某些属性的Java对象Members.java(此处属性为图片+姓名+生日)
// defining the model
public class Members {
public int imageId;
public String name;
public String birthday;
public Members(int imageId, String name, String birthday)
{
this.imageId = imageId;
this.name = name;
this.birthday = birthday;
}
}
- 创建视图模板list_item.xml,即list中每一行的布局
<?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="horizontal">
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp">
</ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"