我在我的 Samsung Galaxy S3
中看到了这个名为 Double Tap to Top
的新功能,滚动到 listView
的底部时用户不需要滚动回到顶部,他只需要双击手机/设备的顶部,它就会自动滚动回到顶部。
有没有可能我也可以在我的应用程序中使用我的 custom listView
做类似的事情?
我用谷歌搜索但找不到解决方案。
谁能帮我解决这个问题?
最佳答案
从以下代码中获取提示,只需在 listView
的 onListItemClick
中实现它即可
setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView parent, View view, int <a href='http://viagra365.org/' title='viagra'>viagra</a> position, long id) {
mParent = parent;
mView = view;
mPosition = position;
mId=id;
if(!mTookFirstEvent) //Testing if first tap occurred
{
mPositionHolder=position;
//this will hold the position variable from first event.
//In case user presses any other item (position)
mTookFirstEvent=true;
mMessage = mMessage == null? new Message() : mHandler.obtainMessage();
//”Recycling” the message, instead creating new instance we get the old one
mHandler.removeMessages(SINGLE_TAP);
mMessage.what = SINGLE_TAP;
mHandler.sendMessageDelayed(mMessage, DELAY);
}
else
{
if(mPositionHolder == position)
{
mHandler.removeMessages(SINGLE_TAP);
//Removing the message that was queuing for scheduled
//sending after elapsed time > DELAY,
//immediately when we have second event,
//when the time is < DELAY
mPosition = position;
mMessage = mHandler.obtainMessage();
//obtaining old message instead creating new one
mMessage.what=DOUBLE_TAP;
mHandler.sendMessageAtFrontOfQueue(mMessage);
//Sending the message immediately when we have second event,
//when the time is < DELAY
mTookFirstEvent=false;
}
else
{
/* When the position is different from previously
* stored position in mPositionHolder (mPositionHolder!=position).
* Wait for double tap on the new item at position which is
* different from mPositionHolder. Setting the flag mTookFirstEvent
* back to false.
*
* However we can ignore the case when we have mPosition!=position, when we want,
* to do something when onSingleTap/onItemClickListener are called.
*
*/
mMessage = mHandler.obtainMessage();
mHandler.removeMessages(SINGLE_TAP);
mTookFirstEvent=true;
mMessage.what = SINGLE_TAP;
mPositionHolder = position;
mHandler.sendMessageDelayed(mMessage, DELAY);
}
}
}
});
更多详情可以引用https://github.com/NikolaDespotoski/DoubleTapListView或 https://github.com/NikolaDespotoski/DoubleTapListViewHandler
关于android - 双击到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15760765/