android中ListView控件
今天学习了ListView控件和页面跳转,下面大致介绍下:
第一步:创建显示内容的文件vlist.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="wrap_content"
android:orientation="horizontal"
android:background="#31B6E7" > <ImageView android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5px" /> <LinearLayout android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/txtid"
android:layout_width="0dp"
android:layout_height="0dp"/>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="22px"/>
<TextView android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="13px"/> </LinearLayout>
</LinearLayout>
下面是主Activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" > <TextView
android:id="@+id/txtDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" > <ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1" >
</ListView>
</LinearLayout> </RelativeLayout>
下面是对应的代码:
private void bindData() {
ListView lv = (ListView)findViewById(R.id.listView1);
SimpleAdapter adapter= new SimpleAdapter(this, getData(), R.layout.vlist,
new St ring[]{"id","img","title","info"},
new int[]{R.id.txtid, R.id.img,R.id.title,R.id.info});
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
ListView listView = (ListView)arg0;
HashMap<String, String> map = (HashMap<String, String>)listView.getItemAtPosition(arg2);
String id = map.get("id");
String info = map.get("info");
TextView txtDescription = (TextView)findViewById(R.id.txtDescription);
StringBuilder sb = new StringBuilder();
sb.append(getResources().getText(R.string.detail));
sb.append(":"+info);
sb.append("-----id:"+id);
txtDescription.setText(sb);
}
});
}
private List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = null;
for (int i = 0; i < 10; i++) {
map = new HashMap<String, Object>();
map.put("id", i);
map.put("title", "Title");
map.put("info", "google "+(i+1));
map.put("img", R.drawable.ic_action_search);
list.add(map);
}
return list;
}
上面即ListView的呈现和Click Item 的使用方法
android中ListView控件的更多相关文章
- Android中ListView控件的使用
Android中ListView控件的使用 ListView展示数据的原理 在Android中,其实ListView就相当于web中的jsp,Adapter是适配器,它就相当于web中的Servlet ...
- android中ListView控件&&onItemClick事件中获取listView传递的数据
http://blog.csdn.net/aben_2005/article/details/6592205 本文转载自:android中ListView控件&&onItemClick ...
- Android中ListView 控件与 Adapter 适配器如何使用?
一个android应用的成功与否,其界面设计至关重要.为了更好的进行android ui设计,我们常常需要借助一些控件和适配器.今天小编在android培训网站上搜罗了一些有关ListView 控件与 ...
- android中ListView控件最简单的用法
创建一个活动,在xml文件中添加一个ListView控件,id定义为list1,并且设置为满屏显示,代码如下: <ListView android:id="@+id/list1&quo ...
- Android中ExpandableListView控件基本使用
本文採用一个Demo来展示Android中ExpandableListView控件的使用,如怎样在组/子ListView中绑定数据源.直接上代码例如以下: 程序结构图: layout文件夹下的 mai ...
- android中RecyclerView控件实现点击事件
RecyclerView控件实现点击事件跟ListView控件不同,并没有提供类似setOnItemClickListener()这样的注册监听器方法,而是需要自己给子项具体的注册点击事件. 本文的例 ...
- C# winform项目中ListView控件使用CheckBoxes属性实现单选功能
C# winform项目中ListView控件使用CheckBoxes属性实现单选功能 在做项目时需要使用ListView控件的CheckBoxes属性显示,还要在点击行时自动选中CheckBoxes ...
- android中RecyclerView控件实现瀑布流布局
本文是在之前文章的基础上做的修改:android中RecyclerView控件的使用 1.修改列表项news_item.xml: <?xml version="1.0" en ...
- android中RecyclerView控件的列表项横向排列
本文是在上一篇文章的基础上做的修改:android中RecyclerView控件的使用 1.修改列表项news_item.xml:我这里是把新闻标题挪到了新闻图片的下面显示 <?xml vers ...
随机推荐
- AC-BM算法原理与代码实现(模式匹配)
AC-BM算法原理与代码实现(模式匹配) AC-BM算法将待匹配的字符串集合转换为一个类似于Aho-Corasick算法的树状有限状态自动机,但构建时不是基于字符串的后缀而是前缀.匹配 时,采取自后向 ...
- c#中使用SESSION需要注意的几个问题
C#的SESSION和其它程序中的SESSSION可能有一点的不同,下面讲下哪飞网程序员遇到的一个地方使用SESSION的问题.希望对大家有所帮助 一.在页面中用SESSION,存值session[& ...
- WordPress get_allowed_mime_types函数(wp-includes/functions.php)存在跨站脚本漏洞
漏洞版本: WordPress 3.6 漏洞描述: CVE ID:CVE-2013-5738 WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设 ...
- 用vmware安装gho文件
方法1:diskgenius+ghostexp 用vm新建一个空白硬盘虚拟机, 记住虚拟机文件的存储位置, 最好将默认的scsi硬盘移除另外新建ide的硬盘(否则可能开机蓝屏),然后用host机DIS ...
- MD5Helper辅助类
DES加密和解密 public class MD5Helper { ///DES加密 ///sKey public string MD5Encrypt(string pToEncrypt, strin ...
- EntityFramework在不同数据库下的配置
1.SQLServer: <connectionStrings> <add name="EntityDesignEntities" connectionStrin ...
- Windows 10 录音上的一个问题
最近升级到了Windows 10,结果在开发程序时发现,无论采用什么方法,都无法正常录制单声道的声音,虽然有迂回的方法解决问题,
- Android 播放视频并获取指定时间的帧画面
最近做的项目要求既能播放视频(类似于视频播放器),又能每隔1s左右获取一帧视频画面,然后对图片进行处理,调查了一周,也被折磨了一周,总算找到了大致符合要求的方法.首先对调查过程中涉及到的方法进行简单介 ...
- linux关于bashrc与profile的区别(转)
转载自:http://www.cnblogs.com/hongzg1982/articles/2101792.html bashrc与profile的区别 要搞清bashrc与profile的区别,首 ...
- POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang
Problem Description As we all know, machine scheduling is a very classical problem in computer scien ...