2

I have a listview with item. Click on an item it goes to another activity. My problem is on clicking on multiple items (say 3 0r4 ) all clicked are loaded. But i dont need it. Only want to load 1 item at a time. Tested on HTC one,samsung galaxy s plus. Please help.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
hayasqb
  • 21
  • 4

3 Answers3

3

You can detect multitouch and neglect it.

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);

}

Sourav301
  • 1,259
  • 1
  • 14
  • 24
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);
                    }
                }
            });
0

To stop this, Use this in your list view.

android:splitMotionEvents="false"
Nehemiah Narzary
  • 336
  • 4
  • 11