Listview的点击事件
上篇文章总结了如何自定义listview的显示内容,然而listview不能只是提供显示功能,还必须能够点击它显示一些东西;
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
Fruit fruit = fruitList.get(position);
}
});
我们使用了 setOnItemClickListener()方法来为 ListView 注册了一个监听器,当用户点击了 ListView 中的任何一个子项时就会回调 onItemClick()方法,在这个方法中可以通过 position 参数判断出用户点击的是哪一个子项。
想像我们在用淘宝购物,点击列表我们应该得到另一个页面,下面是我写的另一个例子的代码
lView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// TODO Auto-generated method stub
Article article = articleList.get(position);
Intent intent = new Intent(NewsActivity.this,ArticleActivity.class);
intent.putExtra("url", article.getUrl());
startActivity(intent);
}
});
这个例子我写的一个新闻app,点击文章内容可以启动另一个活动,并通过 putExtra()方法传递了一个url。注意这里 putExtra()方法接收两个参数,第一个参数是键,用于后面从 Intent中取值,第二个参数才是真正要传递的数据。在另一个活动中,用getintent方法获得启动这个活动的intent,调用这个intent对象的getstringextra方法。代码如下
Intent intent = getIntent();
String urlString = intent.getStringExtra("url");//get的是键值
Listview的点击事件的更多相关文章
- Android学习---ListView的点击事件,simpleAdapter和arrayadapter,SimpleCursoAdapter的原理和使用
如题,本文将介绍 listview的点击事件,simpleAdapter和arrayadapter的原理和使用. 1.ListView的注册点击事件 //注册点击事件 personListView.s ...
- ListView的item中有button和checkbox,listview的点击事件无效
ListView的item中有button和checkbox,listview的点击事件无效,解决办法: 在item布局文件中的根控件中添加属性设置: android:descendantFocusa ...
- Android ListView item 点击事件失效问题的解决
关于ListView点击无效,item无法相应点击事件的问题,网上有很多, 大致可分为俩种情况, 一种是 item中存在 ImageButton 等可以点击的组件,这会抢先获得ListView的焦点. ...
- ListView实现点击事件以及总结
差点吓死我了,好不容易写的博客没有了,还好有自动保存功能,不然我真的是呜呜... ---恢复内容开始--- 开学一个月了,终于可以看见自己的作品雏形了. 从一个小白到现在半年了,觉得日子过得比较充实, ...
- ListView中加入Button后,Button的点击事件和ListView的点击事件冲突
1.在ItemView配置的xml文件里的根节点加入属性android:descendantFocusability="blocksDescendants" 2.在要加入事件的控件 ...
- Firemonkey ListView 点击事件
Firemonkey ListView 的点击事件一直让人摸不着头绪(各平台触发规则不太相同),因为它提供了点击相关的事件就有如下: OnChange:改变项目触发. OnClick:点击触发. On ...
- 在Activity中响应ListView内部按钮的点击事件
最近交流群里面有人问到一个问题:如何在Activity中响应ListView内部按钮的点击事件,不要在Adapter中响应? 对于这个问题,我最初给他的解答是,在Adapter中定义一个回调接口,在A ...
- Listview点击事件
listview = (ListView) findViewById(R.id.listview); // 填充data数据 data = new ArrayList<String>(); ...
- 在Activity中响应ListView内部按钮的点击事件的两种方法!!!
在Activity中响应ListView内部按钮的点击事件的两种方法 转载:http://www.cnblogs.com/ivan-xu/p/4124967.html 最近交流群里面有人问到一个问题: ...
随机推荐
- C#的注释和快速开启工具的命令
1.注释的方法 1)sqlserver中,单行注释:—— 多行注释:/****/ 2)C#中,单行注释:// 多行注释:/****/ 3)C#中多行注释的快捷方式:启用ctrl+E+C ,撤 ...
- 获取datatable更新之前的数据
string dd = ds.Tables[0].Rows[0][0, DataRowVersion.Original].ToString() ;
- centos下完全卸载mysql
版权声明:本文为博主原创文章,未经博主允许不得转载. yum方式安装的MySQL 1.yum remove mysql mysql-server mysql-libs compat-mysql51 2 ...
- Exchange 2013 、Lync 2013、SharePoint 2013
Office办公系列 在企业中广泛应用,目前服务的客户当中,部分客户已经应用到了 Exchange.Lync.CRM.SharePoint等产品,在开发当中多多少少会涉及到集成,为了更好的服务客户.了 ...
- css设置height 100%
需要显式设置html,body为100%,body是相对于html,wrapper是相对于body html,body{ height: 100%; } .wrapper{ height: 100; ...
- ASP.NET MVC中将数据从Controller传递到视图
ASP.NET MVC中将数据从Controller传递到视图方法 1.ViewData ViewData的类型是字典数据,key-value 如:ViewData["Data"] ...
- How to upgrade workflow assembly in MOSS 2007
This problem generally start when you are having an existing custom workflow and there are instances ...
- 谷歌的网页排序算法(PageRank Algorithm)
本文将介绍谷歌的网页排序算法(PageRank Algorithm),以及它如何从250亿份网页中捞到与你的搜索条件匹配的结果.它的匹配效果如此之好,以至于“谷歌”(google)今天已经成为一个被广 ...
- 异步post请求之代理方法
#import "ViewController.h" #import "Header.h" @interface ViewController ()<NS ...
- 多种cell混合使用
有时候我们会碰到一个tableView上有多种cell,这个时候就需要定义多种cell,根据条件判断,当满足某个条件的时候选择某个cell 先看plist文件: Person.h #import &l ...