GridView、listview实现双击监听的一种较简单方法

gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        int p1 = MAX;
        int p2 = 0;
        double t1 = -1000000;
        double t2 = 1;
    
@Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {
        
        t2 = System.currentTimeMillis();
        p2 = position;
        if(p2 == p1 && t2 - t1 <1000){
        
           //此处填写双击逻辑
            
         
        Log.d("TAG", "onItemClick: the position is = "+ String.valueOf(position) + "\n and the id of it is = " +String.valueOf(id));
        
       }else{
            
            //此处填写单击逻辑
            
            p1 = p2;
            t1 = t2;
        }

你可能感兴趣的:(GridView、listview实现双击监听的一种较简单方法)