Fast taps (clicks) on RecyclerView opens multiple Fragments

前端 未结 10 904
渐次进展
渐次进展 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:00

    Too late but it can work for other people:

    recyclerAdapter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int id = ....
                if(id == 1){
                    view.setClickable(false); //add this
                    Intent a = new Intent...
                    startActivity(a);
    
                }else if(id == 2){
                    view.setClickable(false);
                    Intent b = ...
                    startActivity(b);
                }
            }
        });
    

    Fragment - onResume()

    @Override
    public void onResume() {
        super.onResume();
        Objects.requireNonNull(getActivity()).invalidateOptionsMenu();
        recyclerView.setAdapter(recyclerAdapter); //add this
    }
    

    It works for me, i don't know if it's correct.

提交回复
热议问题