如何在Andoid ListView中获取选定的项目索引? [英] How to get selected item index in andoid listview ?

查看:79
本文介绍了如何在Andoid ListView中获取选定的项目索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:)

我有一个列表视图,我想获取选定的项目索引以对其进行一些处理

如何获得此索引为整数值?

这是我的代码:

Hi all :)

I have a listview, and I want to get the selected item index to do some process on it

how can I get this index as an integer value ?

this is my code:

final ListView list = (ListView)findViewById(android.R.id.list);
		list.setClickable(true);
		list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

		public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
	    
		  }
		});



谢谢:)



thanks all :)

推荐答案

阅读文档.您不是第一个愿意发现...的人.

http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html [^ ]

http://developer.android.com/reference/android/widget/ListView.html [ ^ ]

有关使用ListView的教程:
http://developer.android.com/resources/tutorials/views/hello-listview.html [^ ]
Read the documentation. You are not the first person ever willing to find out...

http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html[^]

http://developer.android.com/reference/android/widget/ListView.html[^]

Tutorial on using ListView:
http://developer.android.com/resources/tutorials/views/hello-listview.html[^]


public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {	    
		  }



int位置将为您提供int中的选定项目索引.



The int position will give you the selected item index in int.


我的用户如下所示,工作正常

i user like below and working nice

mylistview.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				MyObject selection = (MyObject) arg0.getItemAtPosition(arg2);
				
			}
		});



不同的是
我没有使用



the different is
i havent use

list.setClickable(true);


并放置

@Override

属性


这篇关于如何在Andoid ListView中获取选定的项目索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆