如何最好地处理一扔手势为Android ListActivity [英] How to best handle fling gesture for Android ListActivity
问题描述
我有一个 ListActivity
在主视图中的Android应用程序。该列表包含一个的LinearLayout
与的TextView
和隐藏的删除按钮。删除按钮将被默认隐藏。我想用一个一扔姿态展现的按钮。我能够检测一扔手势感谢质疑# 937313 的计算器。这不是我清楚如何确定哪些项目在列表中被扔,因为onTouch监听器监听的ListView
。该项目不一定选择成getSelected *方法不能可靠地使用。我现在用的是 SimpleListAdaptor
所以我没有直接访问查看对象的的ListView
。
I have an Android app with a ListActivity
in the main view. The list contains a LinearLayout
with a TextView
and a hidden delete Button. The delete Button will be hidden by default. I want to use a fling gesture to show the button. I am able to detect the fling gesture thanks to question #937313 on stackoverflow. It's not clear to me how to determine which item in the list was flung, since the onTouch listener listens to the ListView
. The item is not necessarily selected so getSelected* methods can't be used reliably. I am using the SimpleListAdaptor
so I don't have direct access to the View Objects in the ListView
.
任何想法?
推荐答案
尝试使用<一个href="http://developer.android.com/reference/android/widget/AbsListView.html#pointToPosition%28int,%20int%29"相对=nofollow> AbsListView.pointToPosition()确定为X的列表项,Y在您的列表视图坐标。
Try using AbsListView.pointToPosition() to determine the list item for the X,Y coordinate in your list view.
如果您使用的是来自# 937313 的配方,你应该能够覆盖 onFling( )
或多或少如下:
If you're using the recipe from #937313, you should be able to override onFling()
more or less as follows:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
Toast.makeText(listAdapter.getItem( listView.pointToPosition( (int) e1.getX(), (int) e1.getY() ).toString() );
return super.onFling();
} catch( Exception e ) {
// do nothing
}
}
这篇关于如何最好地处理一扔手势为Android ListActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!