SimpleAdapter 列表

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/aa"
        android:id="@+id/iv1"/>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:gravity="center_vertical"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="名字;aaa"
            android:id="@+id/iv2"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="内容;aaa"
            android:id="@+id/iv3"/>

    </LinearLayout>

</LinearLayout>

准备单个式样

<?xml version="1.0" encoding="utf-8"?>
<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"
    >

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/lv2"></ListView>


</LinearLayout>

整个显示界面

package com.hanqi.zuoye;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class liebiao2Activity extends AppCompatActivity {
    ListView lv2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_liebiao2);
       lv2=(ListView)findViewById(R.id.lv2);

        //数据集合 Layout
        List<Map<String,Object>>lm=new ArrayList<Map<String, Object>>() {};
           Map<String,Object> map=new HashMap<>();
        map.put("img",R.drawable.a);
        map.put("name","怪兽");
        map.put("content","怪兽介绍");
        lm.add(map);
        map=new HashMap<>();
        map.put("img",R.drawable.aa);
        map.put("name","怪兽2");
        map.put("content","怪兽介绍2");
        lm.add(map);
        map=new HashMap<>();
        map.put("img",R.drawable.aaa);
        map.put("name","怪兽3");
        map.put("content","怪兽介绍3");
        lm.add(map);

        // 数组  定义key的数组
        String []str={"img","name","content"};
        //获取模块的id
        int[]ids={R.id.iv1,R.id.iv2,R.id.iv3,};

        //创建
//content ,要放入的集合,式样视图文件,存放集合key的数组,式样中子式样的id,对应放入位置
SimpleAdapter simpleAdapter=new SimpleAdapter(this,lm,R.layout.liebiao2,str,ids); lv2.setAdapter(simpleAdapter); } }

java代码

原文地址:https://www.cnblogs.com/storm47/p/5501991.html