我在我的Samsung Galaxy S3
中看到了这个名为Double Tap to Top
的新功能,在滚动到listView
底部时,用户无需滚动到顶部,只需双击即可手机/设备的顶部,它会自动滚动回到顶部。
在我的应用程序中我是否有可能与custom listView
类似?
我用谷歌搜索但找不到解决方案。
任何人都可以帮我这个吗?
答案 0 :(得分:0)
从以下代码中获取提示,只需在onListItemClick
listView
中实施即可
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