人生到头来,就是不断放下,但永远最|

durtime

园龄:4年8个月粉丝:10关注:1

每日日报

SimpleAdapter   

 

复制代码
1.public class MainActivity extends Activity {
2.    @Override
3.    protected void onCreate(Bundle savedInstanceState) {
4.        super.onCreate(savedInstanceState);
5.        setContentView(R.layout.activity_main);
6.       ListView lv_list =  (ListView) findViewById(R.id.lv_list);
7.       //List<map> 用来填充数据的
8.       List<Map<String, String>> data = new ArrayList<Map<String,String>>();
9.       Map<String, String> map1 = new HashMap<String, String>();
10.       map1.put("title", "中国足球又输了");
11.       map1.put("content", "2016冲击失败");
12.       data.add(map1);
13.       Map<String, String> map2 = new HashMap<String, String>();
14.       map2.put("title", "沪android12期高薪就业");
15.       map2.put("content", "平均薪水20K");
16.       data.add(map2);
17.    String[] from ={"title","content"};
18.    int[] to = {R.id.tv_title,R.id.tv_content};
19.    //第二个参数 数据map的List
20.    //第三个参数 用来显示数据的布局文件
21.    //第四个参数 String数组 数据List中 每一条数据的 key
22.    //第五个参数 数据List中 的文字内容 对应的 要显示此内容的 textView的id
23.    SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.item2, from, to);
24.       lv_list.setAdapter(adapter);
25.    }
26.}
复制代码

 

条目的布局文件

 

复制代码
1.<?xml version="1.0" encoding="utf-8"?>
2.<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3.    xmlns:tools="http://schemas.android.com/tools"
4.    android:layout_width="match_parent"
5.    android:layout_height="match_parent"
6.    tools:context=".MainActivity" >
7.
8.   <ImageView 
9.       android:id="@+id/iv_icon"
10.       android:layout_width="wrap_content"
11.       android:layout_height="wrap_content"
12.       android:src="@drawable/ic_launcher"
13.       android:layout_margin="5dp"/>
14.   <TextView
15.       android:id="@+id/tv_title"
16.       android:layout_toRightOf="@id/iv_icon"
17.       android:layout_height="wrap_content"
18.       android:layout_width="wrap_content"
19.       android:layout_margin="7dp"
20.       android:text="北京今年装修要多少钱"
21.       android:textSize="18sp"
22.       />
23.   
24.   <TextView
25.       android:id="@+id/tv_content"
26.       android:layout_toRightOf="@id/iv_icon"
27.       android:layout_below="@id/tv_title"
28.       android:layout_height="wrap_content"
29.       android:layout_width="wrap_content"
30.       android:text="获得报价"
31.       android:textColor="#999999"
32.       android:layout_marginLeft="8dp"
33.       android:textSize="16sp"
34.       />
35.
36.</RelativeLayout>
复制代码

 

本文作者:durtime

本文链接:https://www.cnblogs.com/durtime/p/14836197.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   durtime  阅读(41)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
展开