文本drwable无法在RecycleView
上设置。
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.list_row, viewGroup, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
ExpensesTable nature = expensesItem.get(i);
viewHolder.category.setText(nature.getCategory());
viewHolder.money.setText(nature.getMoney());
viewHolder.date.setText(nature.getDate());
viewHolder.time.setText(nature.getTime());
viewHolder.notes.setText(nature.getNotes());
TextDrawable drawable = mDrawableBuilder.build(String.valueOf(nature.getCategory().charAt(0)), mColorGenerator.getColor(nature.getCategory()));
viewHolder.imageView.setImageDrawable(drawable);
}
我尝试这个但是无法设置textdrwable的适配器,但它在适配器上显示NullPointerException