zoukankan      html  css  js  c++  java
  • ListView

    package com.bgxt.datatimepickerdemo;

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

    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;

    public class SimpleAdapterActivity extends Activity {
    private ListView listview;
    private SimpleAdapter simpleAdapter;
    private List<Map<String, Object>> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listviewarrayadapter);
    listview = (ListView) findViewById(R.id.lvArray);
    //填充数据
    putData();
    //这里使用当前的布局资源作为ListView的模板。
    //使用这种方式,SimpleAdapter会忽略ListView控件,仅以ListView之外的控件作为模板。
    simpleAdapter = new SimpleAdapter(SimpleAdapterActivity.this, data,
    R.layout.activity_listviewarrayadapter, new String[] { "icon",
    "name", "ss" }, new int[] { R.id.ivIcon, R.id.tvName,
    R.id.tvSS });
    listview.setAdapter(simpleAdapter);
    }

    private void putData()
    {
    data=new ArrayList<Map<String,Object>>();
    Map<String, Object> map1=new HashMap<String, Object>();
    map1.put("icon", R.drawable.item1);
    map1.put("name", "简爱");
    map1.put("ss", "风将绿了夜的途");
    Map<String, Object> map2=new HashMap<String, Object>();
    map2.put("icon", R.drawable.item2);
    map2.put("name", " 陌 陌");
    map2.put("ss", "寻找你,你在我心中__。");
    Map<String, Object> map3=new HashMap<String, Object>();
    map3.put("icon", R.drawable.item3);
    map3.put("name", "汐颜");
    map3.put("ss", "最新分享:中国合伙人正能量22句话...");
    Map<String, Object> map4=new HashMap<String, Object>();
    map4.put("icon", R.drawable.item4);
    map4.put("name", "花仙子");
    map4.put("ss", " ");
    data.add(map1);
    data.add(map2);
    data.add(map3);
    data.add(map4);
    }
    }

  • 相关阅读:
    Java开发常用Util工具类
    冒泡排序
    EMQ 消息服务器
    将jar文件包打成exe文件
    mina框架搭建tcp服务器:编写自定义协议及编解码器
    SpringBoot中定时任务的设置
    SpringBoot项目+Shiro(权限框架)+Redis(缓存)集成
    计算两个时间之间的天数
    关于extern的使用
    ADC采样间隔问题+TRGO作为ADC的触发源头
  • 原文地址:https://www.cnblogs.com/zhaozilongcjiajia/p/10405973.html
Copyright © 2011-2022 走看看