3
我看到這個新功能在我的Samsung Galaxy S3
調用Double Tap to Top
滾動到底部的listView
用戶不需要回滾到頂部,他只需要雙擊在手機/設備的頂部,它自動滾動回頂部。 我的應用程序中是否還有可能與我的custom listView
類似? 我已經使用Google搜索,但找不到解決方案。 任何人都可以幫助我嗎?從下面的代碼雙擊到頂部
我看到這個新功能在我的Samsung Galaxy S3
調用Double Tap to Top
滾動到底部的listView
用戶不需要回滾到頂部,他只需要雙擊在手機/設備的頂部,它自動滾動回頂部。 我的應用程序中是否還有可能與我的custom listView
類似? 我已經使用Google搜索,但找不到解決方案。 任何人都可以幫助我嗎?從下面的代碼雙擊到頂部
採取暗示只是實現它在你的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);
}
}
}
});
onListItemClick
欲瞭解更多詳細信息,您可以參考https://github.com/NikolaDespotoski/DoubleTapListView或https://github.com/NikolaDespotoski/DoubleTapListViewHandler
我認爲你必須實現onTouchListner您的ListView然後檢查doubleTap並調用適配器的scrollToTop()方法。 – Ankit
那麼我們如何檢查設備或手機頂部的雙擊? – Syn3sthete
查看下面的答案。 – Ankit