3

我在我的通话中看到了这个新功能Samsung Galaxy S3Double Tap to Top在滚动到底部时,listView用户不需要滚动回顶部,他只需要在电话/设备顶部双击,它就会自动滚动回顶部。有没有可能我也可以custom listView在我的应用程序内部做类似的事情?我用谷歌搜索但找不到解决方案。谁能帮我这个?

4

1 回答 1

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/DoubleTapListViewhttps://github.com/NikolaDespotoski/DoubleTapListViewHandler

于 2013-04-03T17:04:04.433 回答