0
在我的項目中,我使用的是recyclerview,當我點擊其中的元素時,它應該打開另一個片段或活動(取決於什麼元素),但是當我點擊兩次它打開的某個項目時2個片段或活動的副本。RecyclerView點擊兩次
所以我的代碼是:
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);
}
這就是我如何處理點擊的片段:
@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);
}
所以,我怎樣才能防止這種兩次點擊? :)
我能做到這一點,但是,當用戶返回到這個名單他發現他需要這樣的項目是不可點擊。 –
您可以在startActivity(intent)後再次啓用它; – toshkinl