我有一个包含对象列表的回收站视图。这是我的代码:
filter
设置适配器的代码
public class Active_Adapter extends RecyclerView.Adapter<Active_Adapter .ViewHolder> {
Context con;
List<ModelQRActiveData> modelQRActiveDatas;
FragmentManager fragmentManager;
public QR_Active_Adapter(Context con, List<ModelQRActiveData> modelQRActiveDatas, FragmentManager fragmentManager){
this.con= con;
this.modelQRActiveDatas = modelQRActiveDatas;
this.fragmentManager = fragmentManager;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(con).inflate(R.layout.single_reward, parent, false);
ViewHolder holder = new ViewHolder(v);
return holder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final ModelQRActiveData modelQRActiveData = modelQRActiveDatas.get(position);
holder.tv_title_reward.setText(modelQRActiveData.getOffer_name());
holder.tv_reward_code.setText(modelQRActiveData.getCoupon_code());
holder.tv_cafe_name_bold.setText(modelQRActiveData.getVenue_name());
String add=modelQRActiveData.getLocation().getAddress_line_3()+" , "+modelQRActiveData.getLocation().getCity();
holder.tv_cafe_address.setText(add);
holder.tv_offer_validity.setText(holder.tv_offer_validity.getText().toString() + " " + modelQRActiveData.getEnd_date());
holder.tv_offer_know_more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//on click here
}
});
if(position == modelQRActiveDatas.size()-1)
{
// Log.e("position", String.valueOf(position));
holder.bottomView.setVisibility(View.VISIBLE);
}
}
//This is not 0
@Override
public int getItemCount() {
return modelQRActiveDatas.size();
}
public class ViewHolder extends RecyclerView.ViewHolder
{
TextView tv_title_reward, tv_reward_code, tv_cafe_name_bold, tv_cafe_address, tv_offer_validity, tv_offer_know_more;
View bottomView;
public ViewHolder(View itemView) {
super(itemView);
tv_title_reward = (TextView) itemView.findViewById(R.id.tv_title_reward);
tv_reward_code = (TextView) itemView.findViewById(R.id.tv_reward_code);
tv_cafe_name_bold = (TextView) itemView.findViewById(R.id.tv_cafe_name_bold);
tv_cafe_address = (TextView) itemView.findViewById(R.id.tv_cafe_address);
tv_offer_validity = (TextView) itemView.findViewById(R.id.tv_offer_validity);
tv_offer_know_more = (TextView) itemView.findViewById(R.id.tv_offer_know_more);
tv_title_reward = (TextView) itemView.findViewById(R.id.tv_title_reward);
bottomView = (View) itemView.findViewById(R.id.bottom_view);
}
}
}
但是它在适配器构造函数之后没有调用方法。像onCreateViewHolder一样,并没有调用所有方法。 getITemCount不是0;