获取选定的项目时,双击列表视图项 [英] Get selected item when double click on listview item
本文介绍了获取选定的项目时,双击列表视图项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是code,显示列表视图项和的onclick监听行动。
Here is the code to display listview items and onclick listener action.
ListView list = (ListView) findViewById(R.id.list);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.list,
android.R.layout.simple_list_item_1);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> l, View v, int position,
long id) {
String sel = (String) adapterView
.getItemAtPosition(position);
Toast.makeText(MyExample.this, "Your selection: " + sel, Toast.LENGTH_SHORT).show();
if (sel.equals("Photos"){
startActivity(new Intent(MyExample.this, Photos.class));
}
}
});
现在,我需要实现选择列表项只在双抽头。我试图用GestureDetector如下:
Now, I need to implement to select the list-item only on double-tapped. I tried to use GestureDetector as follows:
GestureDetector gestureDectector = new GestureDetector(this, new GestureListener());
list.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
gestureDectector.onTouchEvent(event);
return true;
}
});
public class GestureListener extends GestureDetector.SimpleOnGestureListener {
public boolean onDown(MotionEvent e) {
return true;
}
public boolean onDoubleTap(MotionEvent e) {
Log.d("Double_Tap", "Yes, Clicked");
return true;
}
}
但我不知道如何在GestureDetector实现所选择的项目像ItemClickListener并开始根据所选择的列表项其他活动。
But I don't know how to get the selected item in GestureDetector implementation like in ItemClickListener and start another activity based on the selected list-item.
请人帮我。
推荐答案
使用在 onDoubleTap $ c中的列表视图的
pointToPosition
方法$ C>方法:
Use the pointToPosition
method of the listview in your onDoubleTap
method:
int position = list.pointToPosition(e.getX(), e.getY());
这篇关于获取选定的项目时,双击列表视图项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文