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 ...
随机推荐
- js的数据处理记录
mongoDB的mapReduce返回的数据有可能会非常之多,所以单独拎出来先在浏览器里面玩一玩; // 数据源 var arr = [ {"address": "四川汶 ...
- MIT算法导论——第五讲.Linear Time Sort
本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...
- JDBC批处理---(java 对数据库的回滚) .
1先看一下程序: package com.redking.jdbc.demo; import java.sql.Connection; import java.sql.DriverMana ...
- shell 编程基础(1)---初识shellscript
shellscript 是linux下强大的系统管理工具,可以通过bash命令和管道命令直接在linux系统上进行编程,所写的脚本不需要编译就可以执行,对于系统管理而言十分方便. #!/bin/bas ...
- Java API —— HashMap类 & LinkedHashMap类
1.HashMap类 1)HashMap类概述 键是哈希表结构,可以保证键的唯一性 2)HashMap案例 HashMap<String,String> ...
- [从jQuery看JavaScript]-匿名函数与闭包(Anonymous Function and Closure)【转】
(function(){ //这里忽略jQuery所有实现 })(); 半年前初次接触jQuery的时候,我也像其他人一样很兴奋地想看看源码是什么样的.然而,在看到源码的第一眼,我就迷糊了.为什么只有 ...
- 详细讲解 关于Linux静态库和动态库的分析
基本概念 库有动态与静态两种,动态通常用.so为后缀,静态用.a为后缀. 例如:libhello.so libhello.a 为了在同一系统中使用不同版本的库,可以在库文件名后加上版本号为后缀,例如: ...
- android sqlite支持的数据类型
Sqlite3支持的数据类型 :NULL.INTEGER.REAL.TEXT.BLOB 但实际上,sqlite3也接受如下的数据类型: smallint 16 位元的整数. interge ...
- Android开发之EventBus的简单使用
参考: 1.http://blog.csdn.net/harvic880925/article/details/40660137 2.http://blog.csdn.net/harvic880925 ...
- trackr: An AngularJS app with a Java 8 backend – Part III
这是最后我们对trackr系列的一部分.在过去的两的博文中,我们已经向您展示我们使用的工具和框架构建后端和前端.如果你错过了前面的帖子现在你可能会想读他们赶上来. Part I – The Backe ...