在我的项目中,我正在使用recyclerview,当我点击其中的元素时,它应该打开另一个片段或活动(取决于哪个元素),但当我在某个项目上点击两次时,它会打开2个副本片段或活动。
所以我的代码是:
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);
}
那么,我怎样才能防止这次两次点击? :)
答案 0 :(得分:1)
请将以下代码放在item属性中以解决问题
IN: scratchpad "/tmp/foo" utf8 <file-reader> [ my-stream-contents* print ] keep
file contents here
...
--- Data stack:
T{ decoder f ~input-port~ utf8 f }
IN: scratchpad my-stream-contents* print
more file contents here
...
答案 1 :(得分:0)
使用
首次点击后,您基本上可以禁用点击选项 setClickable(false);
您只能点击一次该项目。