系统自带 布局 android.R.layout.simple_expandable_list_item_2,
listItemAdapter = new SimpleAdapter(context, listItem, android.R.layout.simple_expandable_list_item_2, new String[]{"title","url"}, new int[]{android.R.id.text1,android.R.id.text2} );
更多 自带 布局
官方提供了多种ListItem的Layout (R.layout),以下是较为常用的,更多的请查看API DOC的R.layout
http://androidappdocs.appspot.com/reference/android/R.layout.html:
◾android.R.layout.simple_list_item_1 一行text
◾android.R.layout.simple_list_item_2 一行title,一行text
◾android.R.layout.simple_list_item_single_choice 单选按钮
◾android.R.layout.simple_list_item_multiple_choice 多选按钮
◾android.R.layout.simple_list_item_checked checkbox
自定义布局
layout/main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false" android:scrollbars="vertical" > </ListView> </LinearLayout> </LinearLayout>
layout / list.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:padding="10dip" > <TextView android:id="@+id/list_1__1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" > </TextView> <TextView android:id="@+id/list_1__2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" > </TextView> </RelativeLayout>
Wiget2Activity.java
package wiget2.com; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; public class Wiget2Activity extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //////// ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String,String>>(); HashMap<String, String> map1 = new HashMap<String, String>(); HashMap<String, String> map2 = new HashMap<String, String>(); HashMap<String, String> map3 = new HashMap<String, String>(); map1.put("user_name", "zhangshan"); map1.put("user_ip", "192.168.0.1"); map2.put("user_name", "lishi"); map2.put("user_ip", "192.168.0.2"); map3.put("user_name", "wangwu"); map3.put("user_ip", "192.168.0.3"); list.add(map1); list.add(map2); list.add(map3); SimpleAdapter listAdapter = new SimpleAdapter(this, list,R.layout.list, new String[]{"user_name","user_ip"}, new int[]{R.id.list_1__1,R.id.list_1__2} ); setListAdapter(listAdapter); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); System.out.println(" position=" + position + "|| id=" + id); } //长按事件 listView.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Builder builder; builder = new Builder(LoginIndexActivity.this); // builder.setIcon(R.drawable.ic_launcher); builder.setMessage("想要删除该条信息?"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //BroadActivity.this.onCreate(null) ; //相当于把当前activity 重新刷新 } }); builder.setNegativeButton("取消", null); builder.create().show(); return false; //\\ } }); //\\ }
获取 listview 列表每行数据
ArrayList<String> listArray = new ArrayList<String>();// listView data
java.util.Iterator it1 = listItem.iterator(); final String[] getValue = new String[20]; // 返回配置值 数组 0 -9 int f = 0; while (it1.hasNext()) { Object value = it1.next(); String value_str = value.toString(); Pattern pattern; Matcher matcher; pattern = Pattern.compile("ItemValue=(.*?),"); matcher = pattern.matcher(value_str); matcher.find(); getValue[f] = matcher.group(1); f++; } //// ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String,Object>>();
相关推荐
SimpleAdater 简单适配器 配合listView使用 ,将数据展示在列表中 进阶1
自定义适配器 和 SimpleAdater 配合listView使用 ,将数据展示在列表中 进阶2
主要介绍了Android UI:ListView - SimpleAdapter实例详解,SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便,需要的朋友可以参考下
ListView使用simpleAdapter填充实现,数据结构是HashMap,对应的我的博客地址是: http://blog.csdn.net/u012320459/article/details/47667869
简单的ListView,适合新手学习
Android中尝试气泡短信编程初探实例 ListView使用SimpleAdapter适配器详解 具体参考小魏博客:http://blog.csdn.net/xiaowei_cqu/article/details/7045497
《List控件使用---SimpleAdapter使用详解(一)》博文对应源码,该博文讲解了怎样使用simpleAdapter及派生自BaseAdater的ListView的使用方法,博客地址:...
《 List控件使用---SimpleAdapter使用详解(二)》:实现从本地JSON文件生成listView界面;对应博文地址:http://blog.csdn.net/harvic880925/article/details/17288687
改代码主要是针对listview修改指定item字体颜色
《List控件使用---SimpleAdapter使用详解(一)》对应源码,讲解了listView的使用,博文对应地址:http://blog.csdn.net/harvic880925/article/details/17258789
Android SimpleAdapter的多种显示GridView/ListView
Android SimpleAdapter 列表(ListView)、表格(GridView)
基于Eclipse开发平台,Android中使用ListView和三种适配器(ArrayAdaper,SimpleAdapter,BaseAdapter)实现数据的填充。
NULL 博文链接:https://aarongo.iteye.com/blog/1919251
系统自带的list单选满足不了需求,本人特写实现了自定义listview实现单选来和大家分享!
android 的用arrayAdapter和SimpleAdapter的两种ListView 入门专用 不喜勿喷
安卓Android源码——(列表之SimpleAdapter适配).zip
Android中ListView常用的两种适配器ArrayAdapter和SimpleAdapter使用
2.适配器 用来把数据映射到ListView上的中介。 3.数据 具体的将被映射的字符串,图片,或者基本组件。 根据列表的适配器类型,列表分为三种,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter 其中以...
ListView布局方式,通过SimpleAdapter来实现