Android 基础 :SimpleView

专门看了一下Java的map 类型,对Android的帮助的确很大,否则要卡很久才能行,今天学了SimpleView,下回就能学习真正有用的BaseAdapter了


listview主要的步骤:

1.画好activity_main(这必须啊,里面一个ListView就可以),画好adapter_list.xml(这是我认为的最好用的命名方法),里面配好ID

2.List<Map<Srting,String>> = new ArrayList<Map<String,String>>();

 ....构造Map.....

3. ListView listview = (ListView)findViewById(R.id.listview);

SimpleAdapter adapter = new SimpleAdapter(Context context,R.layout.adapter_list,new String[]  = Map里的key, new int[] = list控件里的各种ID)

listview.setAdapter(adapter);


按照上面步骤的源码如下:

1.写activity_main.xml ,这个就是一个LineLayout里面一个match_parent的listview,没什么

写adapter_list.xml,

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imgid"
        android:src="@drawable/ic_launcher"/>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginLeft="40dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Text"
            android:id="@+id/name" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Text"
            android:id="@+id/info" />
    </LinearLayout>

</LinearLayout>


2.Java代码

Map复习:http://blog.csdn.net/qw3752258/article/details/37971775

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        String[] name = new String[30];
        for(int i = 0; i <30 ; i++)
        {
            name[i]="this is name"+Integer.toString(i);
        }
        String[] info = new String[30];
        for(int i = 0; i <30 ; i++)
        {
            info[i]="this is info"+Integer.toString(i);
        }
        String [] imgid = new String[30];
        for(int i = 0; i <30 ; i++)
        {
            imgid[i]=Integer.toString(R.drawable.ic_launcher);
        }
        List<Map<String,String>> list = new ArrayList<Map<String, String>>();
        for(int i = 0; i <30 ; i++)
        {
            Map<String,String> map = new HashMap<String, String>();
            map.put("name",name[i]);
            map.put("info",info[i]);
            map.put("imgid",imgid[i]);
            list.add(map);
        }
        SimpleAdapter simpleAdapter = new SimpleAdapter(this,list,R.layout.adapter_arr,new String[]{"name","info","imgid"},new int[]{R.id.name,R.id.info,R.id.imgid});
        ListView listView1 = (ListView)findViewById(R.id.listView);
        listView1.setAdapter(simpleAdapter);
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值