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 ...
随机推荐
- Learning WCF Chapter2 Messaging Protocols
In Chapter 1,you were introduced to fundamental WCF concepts, 在章节1中,学习了wcf中的基础概念including how t ...
- 【转】Fragment和Activity
原文网址:http://www.cnblogs.com/mengdd/archive/2013/01/11/2856374.html Fragment和Activity的交互 一个Fragment的实 ...
- Java中Map遍历的四种方案
在Java中如何遍历Map对象 方式一 这是最常见的并且在大多数情况下也是最可取的遍历方式.在键值都需要时使用. Map<Integer, Integer> map = new HashM ...
- 解析XML文件示例
项目中要解析Xml文件,于是在工程里找了下前人写例子. 1,SAX(基于事件,效率高,使用声明加载什么). public class MVCConfig { private static MVCCon ...
- Eclipse 下载与安装(2014.12.26——by小赞)
Eclipse网站首页:http://www.eclipse.org/home/index.php Eclipse下载页网址:http://www.eclipse.org/downloads/ 步骤一 ...
- use of undeclared identifier *** , did you mean ***. in xcode
A property is not the same thing os a instance variable, you should read a little bit of them, there ...
- 1 weekend110的hdfs源码跟踪之打开输入流 + hdfs源码跟踪之打开输入流总结
3种形式的元数据,fsimage是在磁盘上,meta.data是在内存上, 我们继续,前面呢,断点是打在这一行代码处, FileSystem fs = FileSystem.get(conf); we ...
- mahout算法源码分析之Collaborative Filtering with ALS-WR (四)评价和推荐
Mahout版本:0.7,hadoop版本:1.0.4,jdk:1.7.0_25 64bit. 首先来总结一下 mahout算法源码分析之Collaborative Filtering with AL ...
- java利用commons-email发送邮件并进行封装
本例中利用commons-email发送邮件并进行封装,支持html内容和附件:Commons Email是Apache的Commons子项目下的一个邮件客户端组件,它是基于JavaMail的,大大简 ...
- gwt中java与js的相互调用
1. java通过jsni调用内部js Button button = new Button("java调用内部jsni的js方法"); button.addClickHandle ...