ListView 自定义Adapter
来源:互联网 发布:文字语音播报软件 编辑:程序博客网 时间:2024/06/01 08:36
public class MainActivity extends Activity { private List<Map<String, Object>> listItems; private String[] names; private String[] ages; private ListView lv; private MyAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); names = getResources().getStringArray(R.array.name); ages = getResources().getStringArray(R.array.age); lv = (ListView) findViewById(R.id.lv); listItems = getListItems(); adapter = new MyAdapter(MainActivity.this, listItems); lv.setAdapter(adapter); } private List<Map<String, Object>> getListItems() { List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); for (int i = 0; i < names.length; i++) { Map<String, Object> map = new HashMap<String, Object>(); map.put("name", names[i]); map.put("age", ages[i]); listItems.add(map); } return listItems; }}
public class MyAdapter extends BaseAdapter { private List<Map<String, Object>> listItems; private LayoutInflater inflater; public final class ListItemView { public TextView tv1; public TextView tv2; } public MyAdapter(Context context, List<Map<String, Object>> listItems) { this.listItems = listItems; inflater = LayoutInflater.from(context); } @Override public int getCount() { // TODO Auto-generated method stub return listItems.size(); } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ListItemView liv; if (null == convertView) { liv = new ListItemView(); convertView = inflater.inflate(R.layout.listitem, null); liv.tv1 = (TextView) convertView.findViewById(R.id.tv1); liv.tv2 = (TextView) convertView.findViewById(R.id.tv2); convertView.setTag(liv); } else { liv = (ListItemView) convertView.getTag(); } liv.tv1.setText((String) listItems.get(position).get("name")); liv.tv2.setText((String) listItems.get(position).get("age")); return convertView; }}
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- listview 自定义Adapter
- listview 自定义Adapter
- 自定义Adapter与ListView
- ListView使用自定义Adapter
- ListView 自定义Adapter
- 自定义ListView的Adapter
- 自定义Adapter的ListView
- 自定义listview的adapter
- Listview的自定义Adapter
- 自定义adapter的listview
- 自定义Adapter填充listview
- 自定义ListView的Adapter
- ListView中Adapter的自定义
- Android 自定义Adapter的Listview
- 自定义ListView使用的Adapter
- 在ListView中自定义Adapter
- Android 自定义Adapter的ListView
- Andoroid自定义Adapter的listView
- Android的WiFi子系统架构
- Android拨号盘,支持T9搜索和号码搜索
- 如何过滤 adb logcat 输出
- Hibernate的简介和Hinbernate的简单模拟实现
- 对vim的配置
- ListView 自定义Adapter
- 完成猜拳小游戏
- FileIO
- 解析XML文件
- 一、lucene3.5的创建和增删改查
- 操作系统实验二 作业调度
- sdram文章精华
- Fuck MySQL (4) 设置root可从任意机器登陆
- 项目4