k.nadonenko
k.nadonenko

Reputation: 628

RecyclerView clicking twice

In my project I'm using recyclerview, and when I click on the element in it it should open another fragment or activity(depends on what element), but when I'm clicking twice on some item it opens 2 copies of fragment or activity.

So my code is:

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public TextView descriptionTV;
    public TextView paymentStatusTV;
    public TextView statusTextView;
    public TextView deliveryStatusTV;
    public NetworkImageView orderImage;
    public ImageView paymentStatusImage;
    public ImageView orderStatusImage;

    public ViewHolder(View itemView, int position) {
        super(itemView);
        descriptionTV = (TextView) itemView.findViewById(R.id.descriptionTV);
        paymentStatusTV = (TextView) itemView.findViewById(R.id.paymentStatusTV);
        statusTextView = (TextView) itemView.findViewById(R.id.statusTextView);
        deliveryStatusTV = (TextView) itemView.findViewById(R.id.deliveryStatusTV);
        orderImage = (NetworkImageView) itemView.findViewById(R.id.orderImage);
        paymentStatusImage = (ImageView) itemView.findViewById(R.id.paymentStatusImage);
        orderStatusImage = (ImageView) itemView.findViewById(R.id.orderStatusImage);
        itemView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(clickListener != null) {
            clickListener.itemClicked(v, getAdapterPosition());
        }
    }
}

public void setClickListener(ClickListener clickListener) {
    this.clickListener = clickListener;
}

public interface ClickListener {
    void itemClicked(View view, int position);
}

And that's how I handle the click in Fragment:

 @Override
public void itemClicked(View view, int position) {

    Bundle bundle = new Bundle();
    Intent intent = new Intent(getActivity(), OrderInformationActivity.class);
    OrderData orderData = cityList.get(position);
    bundle.putString(TAG_ID, orderData.getOrderID());
    intent.putExtras(bundle);
    startActivity(intent);

}

So, how can I prevent this twice clicking? :)

Upvotes: 0

Views: 1986

Answers (3)

Zero
Zero

Reputation: 51

Try adding this to your intent:

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

Upvotes: 0

Piyush
Piyush

Reputation: 5737

Please put below code in item property to solve issue

            android:clickable="true"
            android:focusable="false"
            android:focusableInTouchMode="false"

Upvotes: 1

loshkin
loshkin

Reputation: 1630

You can basically disable the clicking option after the first click with

 setClickable(false);

You will be able to click the item only once.

Upvotes: 0

Related Questions