AdapterView.OnItemSelectedListener.onItemSelected参数问题

youngwolf 2010-11-23 12:21:28
final String[] ContactsFliter = {Contacts.DISPLAY_NAME, BaseColumns._ID};
Cursor c = getContentResolver().query(Contacts.CONTENT_URI, ContactsFliter, null, null, null);
startManagingCursor(c);

ListAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,
c, ContactsFliter,
new int[]{android.R.id.text1, android.R.id.text2});
m_ListView.setAdapter(adapter);
m_ListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
//请问,这里的arg3是什么东西?
}

问题在上面的注释里面,据文档介绍,arg3参数是:The row id of the item that is selected,但上面的例子中,arg3的值居然是数据库里面的BaseColumns._ID的值!百思不得其解。
注:我看的是2.2文档,但用的是2.1 API开发的。
...全文
4022 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
doudoubaba0101 2013-03-12
  • 打赏
  • 举报
回复
arg3是arg1在arg0中的索引id
lu188887 2011-06-15
  • 打赏
  • 举报
回复
我用的ARG2和ARG3的值不一样,ARG2从0开始,ARG3是1,3,5这样递增的数。。。不知道为什么
bill_shou 2011-05-26
  • 打赏
  • 举报
回复
我也有这个疑问,等结果
jsplove 2011-03-21
  • 打赏
  • 举报
回复
打印了一下,arg2和arg3的值貌似一样的
唐小尘 2010-11-23
  • 打赏
  • 举报
回复
public abstract void onItemSelected (AdapterView<?> parent, View view, int position, long id) 

Since: API Level 1 Callback method to be invoked when an item in this view has been selected. Impelmenters can call getItemAtPosition(position) if they need to access the data associated with the selected item.

Parameters
parent The AdapterView where the selection happened
view The view within the AdapterView that was clicked
position The position of the view in the adapter
id The row id of the item that is selected
ameyume 2010-11-23
  • 打赏
  • 举报
回复
BaseColumns
String _ID The unique ID for a row.

The row id of the item that is selected
应该是说的同一个ID吧。
ameyume 2010-11-23
  • 打赏
  • 举报
回复
帮顶,一直没使用过arg3
youngwolf 2010-11-23
  • 打赏
  • 举报
回复
另外想问一下,如果不使用arg3,我如何得到BaseColumns._ID的值呢?
youngwolf 2010-11-23
  • 打赏
  • 举报
回复
回楼上,我对Sql语句做了排序,做了条件判断,无论怎样,arg3的值都等于数据库中BaseColumns._ID的值。
大掌教 2010-11-23
  • 打赏
  • 举报
回复
是pisition,就是第几个item吧。arg0是选的item,是个view对象。arg1是item的id号,从0开始,跟数组的id号类似。arg3就是item的位置。不知道准不准确。arg3一直没怎么用。你可以log输出看看,我觉得你之所以输出的是BaseColumns._ID的值,是因为arg3是从1开始的,你如果查的全表,那么他们的值就是相等的。你可以
log.e(TAG,"arg3 is"+(arg3+1));
log.e(TAG,"BaseColumns._ID is"+BaseColumns._ID);
看看是不是有区别
youngwolf 2010-11-23
  • 打赏
  • 举报
回复
回二三楼,我觉得不一样,比如我把
final String[] ContactsFliter = {Contacts.DISPLAY_NAME, BaseColumns._ID};
改为
final String[] ContactsFliter = {Contacts.DISPLAY_NAME, Contacts.HAS_PHONE_NUMBER};
你觉得会怎样呢?

80,471

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧