OnItemClickListener 的参数详解(转)
转载地址:http://blog.iamzsx.me/show.html?id=147001
我们在使用ListView的时候,一般都会为ListView添加一个响应事件android.widget.AdapterView.OnItemClickListener。本文主要在于对OnItemClickListener的position和id参数做详细的解释,我相信有些人在这上面走了些弯路。
position | The position of the view in the adapter. |
---|---|
id | The row id of the item that was clicked. |
437 public void setAdapter(ListAdapter adapter) {
438 if (mAdapter != null && mDataSetObserver != null) {
439 mAdapter.unregisterDataSetObserver(mDataSetObserver);
440 }
442 resetList();
443 mRecycler.clear();
445 if (mHeaderViewInfos.size() > 0|| mFooterViewInfos.size() > 0) {
446 mAdapter = new HeaderViewListAdapter(mHeaderViewInfos, mFooterViewInfos, adapter);
447 } else {
448 mAdapter = adapter;
449 }
2497 private class PerformClick extends WindowRunnnable implements Runnable {
2498 int mClickMotionPosition;
2500 public void run() {
2501 // The data has changed since we posted this action in the event queue,
2502 // bail out before bad things happen
2503 if (mDataChanged) return;
2505 final ListAdapter adapter = mAdapter;
2506 final int motionPosition = mClickMotionPosition;
2507 if (adapter != null && mItemCount > 0 &&
2508 motionPosition != INVALID_POSITION &&
2509 motionPosition < adapter.getCount() && sameWindow()) {
2510 final View view = getChildAt(motionPosition - mFirstPosition);
2511 // If there is no view, something bad happened (the view scrolled off the
2512 // screen, etc.) and we should cancel the click
2513 if (view != null) {
2514 performItemClick(view, motionPosition, adapter.getItemId(motionPosition));
2515 }
2516 }
2517 }
2518 }
188 public long getItemId(int position) {
189 int numHeaders = getHeadersCount();
190 if (mAdapter != null && position >= numHeaders) {
191 int adjPosition = position - numHeaders;
192 int adapterCount = mAdapter.getCount();
193 if (adjPosition < adapterCount) {
194 return mAdapter.getItemId(adjPosition);
195 }
196 }
197 return -1;
198 }
void onItemClick(AdapterViewparent, View view, int position, long id){
if(id<) {
// 点击的是headerView或者footerView
return;
}
int realPosition=(int)id;
T item=getItem(realPosition);
// 响应代码
}
OnItemClickListener 的参数详解(转)的更多相关文章
- Nginx主配置参数详解,Nginx配置网站
1.Niginx主配置文件参数详解 a.上面博客说了在Linux中安装nginx.博文地址为:http://www.cnblogs.com/hanyinglong/p/5102141.html b.当 ...
- iptables参数详解
iptables参数详解 搬运工:尹正杰 注:此片文章来源于linux社区. Iptalbes 是用来设置.维护和检查Linux内核的IP包过滤规则的. 可以定义不同的表,每个表都包含几个内部的链,也 ...
- chattr的常用参数详解
chattr的常用参数详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在实际生产环境中,有的运维工程师不得不和开发和测试打交道,在我们公司最常见的就是部署接口.每天每个人部署的 ...
- mha配置参数详解
mha配置参数详解: 参数名字 是否必须 参数作用域 默认值 示例 hostname Yes Local Only - hostname=mysql_server1, hostname=192.168 ...
- $.ajax()方法所有参数详解;$.get(),$.post(),$.getJSON(),$.ajax()详解
[一]$.ajax()所有参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注 ...
- linux PHP 编译安装参数详解
linux PHP 编译安装参数详解 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc -- ...
- 【转】jqGrid 各种参数 详解
[原文]http://www.cnblogs.com/younggun/archive/2012/08/27/2657922.htmljqGrid 各种参数 详解 JQGrid JQGrid是一个 ...
- HTML滚动字幕代码参数详解及Js间隔滚动代码
html文字滚动代码 <marquee style="WIDTH: 388px; HEIGHT: 200px" scrollamount="2" dire ...
- mysql5.6主从参数详解
mysql5.6的主从相当的不错,增加了不少参数,提升了主从同步的安全和效率,以下是mysql5.6主从参数详解. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
随机推荐
- lintcode:两个数的和
题目 两数之和 给一个整数数组,找到两个数使得他们的和等于一个给定的数target. 你需要实现的函数twoSum需要返回这两个数的下标, 并且第一个下标小于第二个下标.注意这里下标的范围是1到n,不 ...
- lintcode:哈希函数
题目: 哈希函数 在数据结构中,哈希函数是用来将一个字符串(或任何其他类型)转化为小于哈希表大小且大于等于零的整数.一个好的哈希函数可以尽可能少地产生冲突.一种广泛使用的哈希函数算法是使用数值33,假 ...
- 为什么重写equals方法还要重写hashcode方法?
我们都知道Java语言是完全面向对象的,在java中,所有的对象都是继承于Object类.Ojbect类中有两个方法equals.hashCode,这两个方法都是用来比较两个对象是否相等的. 在未重写 ...
- Sina App Engine(SAE)入门教程(1)
此教程只针对刚接触SAE的小白用户,资深码农.高手请绕道.首先还是一个经典的实例,hello sae. 创建应用 在注册完账号之后,需要到 http://sae.sina.com.cn/?m=myap ...
- pinyin4j
最近在倒腾与搜索相关的拼音检查技术,顺便看了一下中文转拼音开源插件pinyin4j的源码,参考资料:http://blog.csdn.net/hfhwfw/archive/2010/11/23/603 ...
- 新装的win7 64位系统上装了IE11,想调试网页的时候,按F12,工具会出来,但是没法正常使用,出现空白。
Windows专区开了一帖,没人应.这边再开一帖,看看各位遇到过没.如题,新装的win7 64位系统上装了IE11,想调试网页的时候,按F12,工具会出来,但是没法正常使用.尤其是想切换文档模式,只能 ...
- chrome控制台小技巧
对于大多数开发人员来说,chrome控制台最常用的命令就是 console.log()了,然后还有一些其他类似的命令,如: console.info() 提示信息 console.error() ...
- maximum-gap(经过了提示)
下面的分桶个数做的不太好,原来的解法是用的 int gap = (big - small) / vlen; if (gap == 0) { gap = 1; } 下面是现在的Java解法: packa ...
- objcopy
objcopy objcopy [options] infile [outfile] Copy the contents of the input object file to another fil ...
- POJ 1166 The Clocks (爆搜 || 高斯消元)
题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...