当我使用回收器适配器时,不会显示错误,但当我使用recyleroption时,搜索时会显示错误,结果会显示碎片使用情况。
//code
@Override
protected void onBindViewHolder(@NonNull myViewHolder holder, int i, @NonNull Itemmodel itemmodel) {
String quantity=itemmodel.getPquantityet();
String id=itemmodel.getProductid();
String priceavailable=itemmodel.getPriceavailable();
holder.titletv.setText(itemmodel.getProductname());
holder.descriptiontv.setText(itemmodel.getPdescription());
holder.quantitytv.setText(quantity);
holder.pricetv.setText(itemmodel.getPprice());
/* if(priceavailable.equals("true"))
{
holder.pricetv.setText(modelitem.getPprice());
}else {
holder.pricetv.setVisibility(View.GONE);
}*/
if(Integer.parseInt(quantity)<=5){
holder.dangerpic.setVisibility(View.VISIBLE);
}else {
holder.dangerpic.setVisibility(View.GONE);
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Error is on Intent
Intent intent=new Intent(context,BilActivity.class);
intent.putExtra("id",id);
context.startActivity(intent);
}
});
}
似乎context
为空。不知道为什么(也许你在重构过程中犯了一个错误(,但也许可以试着测试一下它是否有效?
Intent intent=new Intent(holder.itemView.context,BilActivity.class);
intent.putExtra("id",id);
holder.itemView.context.startActivity(intent); //You might have to cast this to an activity.