在ListView上检测双击?

时间:2015-05-20 20:11:37

标签: android android-listview

我尝试检测ListView的项目是否收到了双击。为此,我创建了GestureDetector.SimpleOnGestureListener并实现了所有方法。但如果收到onDoubleTap项或项目接收onDown行动,我就无法知道如何获得。

我怎么知道项目是否收到onDoubleTaponDown

监听

public class ListViewTouchListener extends GestureDetector.SimpleOnGestureListener {

    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        float x = e.getX();
        float y = e.getY();
        Log.d("Double Tap", "Tapped at: (" + x + "," + y + ")");

        return true;
    }
}

的ListView

public class EntregaPendenteFrag extends Fragment implements AdapterView.OnItemClickListener,
                                                             AdapterView.OnItemLongClickListener,
                                                             AdapterView.OnTouchListener{
    //setOnTouchListener
    private final String TAG = getClass().getSimpleName() + "->";
    private ProgressDialog progress;

    //vendas entrega pendente
    private ListView lvEntregasPendente;
    private EntregaPendenteListAdapter entregaPendenteLA;
    private List<Venda> listaVenda;

    //itens venda
    private List<ItensVenda> listaItens;

    //dialog de parcelas
    public static AlertDialog alertDialogEntPendente;

    //touch item detector
    private GestureDetector gd;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.entregas_pendente_frag, container, false);

        gd = new GestureDetector(getActivity(), new ListViewTouchListener());

        lvEntregasPendente = (ListView)view.findViewById(R.id.lvEntregasPendente);
        lvEntregasPendente.setOnTouchListener(this);


        return  view;
    }


 @Override
    public boolean onTouch(View v, MotionEvent event) {
        return gd.onTouchEvent(event);
    }

1 个答案:

答案 0 :(得分:0)

这里有一个双击侦听器的示例:   https://developer.android.com/training/gestures/detector.html

你不需要继续在onTouchEvent中调用super吗?

@Override 
public boolean onTouchEvent(MotionEvent event){ 
    this.mDetector.onTouchEvent(event);
    // Be sure to call the superclass implementation
    return super.onTouchEvent(event);
}

So in your code

@Override
public boolean onTouch(View v, MotionEvent event) {
     gd.onTouchEvent(event);
      return super.onTouch( v, event );
}