在列表视图上,只想一次单击一个项目

时间:2013-02-04 05:31:55

标签: android listview

我有一个带有项目的列表视图。单击它转到另一个活动的项目。我的问题是点击多个项目(比如3 0r4)所有点击都被加载。但我不需要它。只想一次加载1个项目。测试HTC one,三星galaxy s plus。请帮忙。

3 个答案:

答案 0 :(得分:3)

您可以检测多点触控并忽略它。

public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub

if(event.getPointerCount() > 1) {
    System.out.println("Multitouch detected!");
    return true;
}
else
    return super.onTouchEvent(event);

}

答案 1 :(得分:0)

    use the follow method can solve that:
    public class FastClickUtil {
          private static long lastClickTime;
            public synchronized static boolean isFastClick() {
                long time = System.currentTimeMillis();   
                if ( time - lastClickTime < 500) {   
                    return true;   
                }   
                lastClickTime = time;   
                return false;   
            }
    }

put that method in your onItemCLickListner  or in your adapter‘s getview like me
    holder.title.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // 解决短时间内同时点击多个item
                    if (FastClickUtil.isFastClick()) {
                        return;
                    } else {
                        Message msg = Message.obtain();
                        msg.what = MSG_WHAT_ONITEM_CLICK;

                        // Bundle data = new Bundle() ;
                        // msg.setData(data) ;
                        msg.obj = menuItem.getTitleResId();
                        getHandler().sendMessage(msg);
                    }
                }
            });

答案 2 :(得分:0)

要停止此操作,请在列表视图中使用它。

android:splitMotionEvents="false"