码迷,mamicode.com
首页 > 其他好文 > 详细

列表视图

时间:2016-05-18 10:29:47      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

package com.hanqi.testapp22;

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 TestActivity8 extends AppCompatActivity {
ListView lv_1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test8);
        lv_1=(ListView)findViewById(R.id.lv_1);
        List<Map<String,Object>> lm=new ArrayList<Map<String,Object>>();
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("img",R.drawable.f1);
        map.put("name","美食1");
        map.put("content", "美食1的内容");
        lm.add(map);

         map=new HashMap<String, Object>();
        map.put("img", R.drawable.f2);
        map.put("name", "美食2");
        map.put("content", "美食的内容");
        lm.add(map);

         map=new HashMap<String, Object>();
        map.put("img",R.drawable.f3);
        map.put("name","美食3");
        map.put("content", "美食3的内容");
        lm.add(map);
        map=new HashMap<String, Object>();
        map.put("img",R.drawable.f4);
        map.put("name","美食4");
        map.put("content","美食4的内容");
        lm.add(map);
        map=new HashMap<String, Object>();
        map.put("img",R.drawable.f5);
        map.put("name","美食5");
        map.put("content","美食5的内容");
        lm.add(map);
        map=new HashMap<String, Object>();
        map.put("img",R.drawable.f6);
        map.put("name","美食6");
        map.put("content","美食6的内容");
        lm.add(map);
        map=new HashMap<String, Object>();
        map.put("img",R.drawable.f7);
        map.put("name","美食7");
        map.put("content","美食7的内容");
        lm.add(map);
        map=new HashMap<String, Object>();
        map.put("img",R.drawable.f8);
        map.put("name","美食8");
        map.put("content","美食8的内容");
        lm.add(map);
        String[] strings={"img","name","content"};
        int [] ids={R.id.iv_1,R.id.tv_1,R.id.tv_2};
        SimpleAdapter simpleadapter=new SimpleAdapter(this,lm,
                R.layout.simple_adapter,strings,ids);
        lv_1.setAdapter(simpleadapter);
    }
}
技术分享
<?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">
    <ImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/f1"
        android:id="@+id/iv_1"/>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="名字=aaa"
            android:id="@+id/tv_1"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="内容=aaa"
            android:id="@+id/tv_2"/>

    </LinearLayout>

</LinearLayout>
View Code

技术分享

列表视图

标签:

原文地址:http://www.cnblogs.com/jiang2538406936/p/5504096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!