- 浏览: 1688543 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (159)
- android 2D (13)
- android 控件 (12)
- android UI (16)
- android 动画 (5)
- android 线程 (3)
- android 数据存储 (15)
- android 基础 (13)
- android xml解析 (1)
- android 多媒体开发 (4)
- android 服务 (4)
- android 安全 (1)
- android WebKit以及相关 (3)
- android 电话 (2)
- android 首选项 (5)
- java基础 (16)
- java 多线程 (1)
- java IO (7)
- android工具使用篇 (1)
- android素材资源区 (1)
- android教程资源区 (1)
- java_android异常记录 (5)
- android问题记录 (1)
- android 推荐资源 (1)
- android 源码篇 (3)
- android SDK (2)
- Google Map For Android (2)
- android 项目问题 (2)
- git (0)
- android API 变化 (1)
- MyEclipse (2)
- Swing组件 (1)
- 活法 (0)
- 其它 (2)
- linux (7)
- 菜鸟的java学习笔记 (0)
- 网络 (0)
- 健康 (1)
- Eclipse在Ubuntu下无法双击启动解决办法 (1)
最新评论
-
tydyz:
引用
android SQLiteOpenHelper使用示例 -
tydyz:
[color=red][/color]
android SQLiteOpenHelper使用示例 -
tydyz:
[flash=200,200][flash=200,200][ ...
android SQLiteOpenHelper使用示例 -
梁家大丫头:
写的还不错,不过不是我需要的。
android 理解和使用自定义权限 -
love_java_cc:
牛逼,太齐全了,收藏
MyEclipse 快捷键大全
什么是listview? 直白点说就是一个能垂直滚动显示列表项的视图View 这些选项的数据来自与这个ListView关联的ListAdapter 这个示例需要2个布局文件 我们先看看运行效果
man.xml
这个布局文件用来设置Activity的布局
user.xml
user.xml用来设置listview的布局方式 在白点说就是 你想怎么显示这个listView
Activity类 注意这个Activity01继承的是ListActivity
ANDROID 2.0 APILEVEL 5
源码和运行效果图见附件
man.xml
这个布局文件用来设置Activity的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/listLinearLayout" android:layout_height="wrap_content" android:orientation="vertical" android:layout_width="fill_parent"> <!-- 我们会自己定义listview的显示方式(在另外一个布局文件里边)不用默认的方式 如果自定义listview的显示方式这里这个 android:id="@id/android:list" 必须这样写 --> <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false" android:scrollbars="vertical"/> <!-- android:drawSelectOnTop="false"此属性用来设置listview上的背景颜色会不会挡住(覆盖)内容 如果这是为false就表示不会覆盖掉 ,这个大家拿例子测试一下效果就明白了 --> </LinearLayout> </LinearLayout>
user.xml
user.xml用来设置listview的布局方式 在白点说就是 你想怎么显示这个listView
<?xml version="1.0" encoding="utf-8"?> <!-- 此布局文件用来定义listview 的显示方式 --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="1dip" android:paddingBottom="1dip" > <TextView android:id="@+id/user_name" android:layout_width="180dip" android:layout_height="30dip" android:textSize="10pt" android:singleLine="true"/> <TextView android:id="@+id/user_ip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right" android:textSize="10pt"/> </LinearLayout>
Activity类 注意这个Activity01继承的是ListActivity
package xiaohang.zhimeng; import java.util.ArrayList; import java.util.HashMap; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.ListView; import android.widget.SimpleAdapter; public class Activity01 extends ListActivity { //ListActivity一个以列表的方式显示数据源、数组的Activity //ListActivity Class Overview(此描述摘自官方文档说的非常清楚了) /*An activity that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. ListActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results. Binding, screen layout, and row layout are discussed in the following sections. Screen Layout ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code) Optionally, your custom view can contain another view object of any type to display when the list view is empty. This "empty list" notifier must have an id "android:empty". Note that when an empty view is present, the list view will be hidden when there is no data to display. The following code demonstrates an (ugly) custom screen layout. It has a list with a green background, and an alternate red "no data" message.*/ @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>(); //一个map对象对应一条数据 map1.put("user_name", "zhangsan"); map1.put("user_ip", "192.168.0.1"); map2.put("user_name", "lisi"); 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这个构造方法的参数说明一下 E文好的直接看E文 /*context The context where the View associated with this SimpleAdapter is running data A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entries specified in "from" resource Resource identifier of a view layout that defines the views for this list item. The layout file should include at least those named views defined in "to" from A list of column names that will be added to the Map associated with each item. to The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter.*/ /** * 参数一 Context 这个不说了 * 参数二 就是上边声明的那个ArrayList对象 * 参数三 这个参数用来指定 我们一行数据 的key 也就是一个map对象的key 上下结合看一下 因为我们一条数据也就是一行 * 对应一个map对象 一个map对象包含2个数据 即 user_name 和 user_ip 这个参数就是用来指定这2个key 这里是通过String数组的方式 * 参数四 大家一看就知道了 意思是 user_name 这条数据用 R.id.user_name 这个TextView显示 user_ip 这条数据用 * R.id.user_ip 显示 */ SimpleAdapter listAdapter = new SimpleAdapter(this,list, R.layout.user, new String[] {"user_name","user_ip"}, new int[] {R.id.user_name,R.id.user_ip}); //这是Adapter setListAdapter()此方法来自ListActivity setListAdapter(listAdapter); } //当我们点击一条数据 或者说一行时 触发的Click事件 @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); //我们输出它的 ID 和 position //ID System.out.println("id------------>" + id); //位置 System.out.println("position--------->" + position); } }
ANDROID 2.0 APILEVEL 5
源码和运行效果图见附件
评论
1 楼
mm4409092
2012-05-05
android listview综合使用示例_结合数据库操作和listitem单击长按等事件处理
http://blog.csdn.net/lk_blog/article/details/7537200
http://blog.csdn.net/lk_blog/article/details/7537200
发表评论
-
android 自定义dialog Demo
2011-11-11 20:20 4168好久没更新博客了,悲剧的菜鸟 就是这样 木有时间. 最近用 ... -
android Notification使用
2011-06-28 20:11 1824直接上链接吧。。 http://www.liuzhaoc ... -
PreferenceScreen 添加自定义View so easy!
2011-06-28 09:39 4312比较简单了 大家自己看吧。 http://stackove ... -
Introducing the Android UI Utilities project (beta)
2011-06-26 13:46 1844博客有一段时间没更新了,前些天 ADT 更新了 11 ... -
android 普通对话框
2011-04-14 09:15 1860string.xml <?xml versio ... -
android ContextMenu
2011-04-13 14:00 5955ContextMenu 继承自 Menu。上下文菜单不同 ... -
android 菜单例子
2011-04-12 21:44 3795也没什么了 就是一个 android菜单的 小例子 ... -
android 获取屏幕的高度和宽度
2010-12-03 16:57 10060Android中的DisplayMetrics 定义 ... -
android 设置全屏显示 和 自适应屏幕
2010-12-03 15:27 7924这个我直接上代码了,比较简单了。还是来张图看看运行效果吧 ... -
android Task简介
2010-11-30 11:32 2745Task 1、 什么是 Task ? Task 翻译成 ... -
android 中将图片放在屏幕中心的方法,不改变图片的大小
2010-11-29 03:02 4059目前只知道2种方法,第一种是通过 设置 和屏幕的边距 ... -
android LayoutInflater 使用示例
2010-11-27 19:37 4170大家好我们这一节讲的是LayoutInflater的使 ... -
android UI 相关常用类简介
2010-11-27 15:12 13592一、Canvas类android.graphics.Canva ... -
android 状态栏提示 (Notification、NotificationManager) 示例
2010-11-20 01:55 7620当有未接电话或短信时,在Android手机的顶部状态栏 ... -
android LayoutParams 简单说明 理解 示例
2010-11-20 00:02 55270简单说说 自己对 android LayoutParam ...
相关推荐
android ListView简单示例
Android ListView简单示例,android studio工程,相应博文请见http://blog.csdn.net/djstavaV/article/details/48653283
Android ListView Tween示例源代码,ListView使用广泛。
android多选ListView示例
Android中使用ArrayAdapter的demo,比较简单,里面用两种方法实现,在MainActivity里面,其中一种被我注释起来了,大家把注释去掉就好了。没有使用自定义适配器,对应的我的博客地址是:...
简单详细的ListView使用示例
android listview 示例源代码 可以得到android listview 的现实 获取listview 的基本方法
ListView使用simpleAdapter填充实现,数据结构是HashMap,对应的我的博客地址是: http://blog.csdn.net/u012320459/article/details/47667869
本文档时对android中LIstView的用法,初学者可以看看了解下
android 常用的listview管理示例。包括listview的里面数据的删除,点击,各种事件。较流行的一种写法,虽然界面比较丑,但具体是实现了。我的博客地址:http://blog.csdn.net/qq_16064871。
只要讲述ListView的应用开发,详细讲述ListView如何使用Adapter添加数据。
android 嵌套的listview示例。就是外面一层listview,这层的item展开又是一个listview。我的博客地址:http://blog.csdn.net/qq_16064871。
android listview圆角示例源代码
这是重写的继承自ArrayAdapter类的自定义适配器方式,数组元素是自定义类。对应的我的博客地址是:http://blog.csdn.net/u012320459/article/details/47667869
android listview item列表全选、单选、反选示例源码,无错误、方便实用。欢迎好评!!谢谢! android listview item列表全选、单选、反选示例源码,无错误、方便实用。欢迎好评!!谢谢!
Android ListView性能优化方案示例,绝对有效的帮助解决ListView的性能优化问题,可以放心继承到项目中。
1.使用 Intent 和 Bundle 实现页面之间的参数传递和跳转; 2.ListView 的使用以及 ListView 中 Item 的点击事件处理 3.button点击事件
android ListView如果从网络加载图片,直接getView,肯定会阻塞UI导致滑动很不流畅,本实例优化了getView中图片的获取。