Fast taps (clicks) on RecyclerView opens multiple Fragments

前端 未结 10 891
渐次进展
渐次进展 2021-02-02 13:37

I have implemented onClick listener to my ViewHolder for my RecyclerView

But when I perform very fast double taps or mouse clicks, it performs the task (opens a seperate

10条回答
  •  隐瞒了意图╮
    2021-02-02 14:08

    • Create a boolean variable in Adapter
    boolean canStart = true;
    
    • Make OnClickListener like
    ViewHolder.dataText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (canStart) {
                canStart = false; // do canStart false 
                // Whatever you want to do and not have run twice due to double tap
            }
        }
    }
    
    • Add setCanStart method in Adapter class:
    public void setCanStart(boolean can){
        canStart = can;
    }
    
    • At last in the fragment's or Activity's ( Where the adapter is assigned to the recyclerview ) add this onResume()
    @Override
        public void onResume() {
            super.onResume();
            mAdapter.setCanStart(true);
        }
    

    Hope it will help :)

提交回复
热议问题