在适用于循环视图的文本中设置适配器

时间:2015-10-31 07:50:33

标签: android adapter android-recyclerview

文本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

error page

0 个答案:

没有答案