我正在尝试将表布局与 recyclerView 一起使用,但它给出了错误:java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TableRow.addView(android.view.View)' 在空对象引用上。
有我的适配器类:
public class CompanyAdapter extends RecyclerView.Adapter<CompanyAdapter.bookViewHolder> {
ArrayList<DataClass> arrayList;
TextView deposit;
TextView purchase;
TextView date;
TableRow tableRow;
TableLayout tableLayout;
public CompanyAdapter(ArrayList<DataClass> arrayList){
this.arrayList = arrayList;
}
@Override
public bookViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
View view =
LayoutInflater.
from(context).inflate(R.layout.company_list_item,parent,false);
return new bookViewHolder(view);
}
@Override
public void onBindViewHolder(bookViewHolder holder, int position) {
DataClass dataClass = arrayList.get(position);
holder.bind(dataClass);
//bookNameTV.setText(dataClass.getBook());
//authorNameTV.setText(dataClass.getAuthor());
}
@Override
public int getItemCount() {
return arrayList.size();
}
public class bookViewHolder extends RecyclerView.ViewHolder{
public bookViewHolder(View itemView) {
super(itemView);
deposit = (TextView) itemView.findViewById(R.id.deposit);
purchase = (TextView) itemView.findViewById(R.id.purchase);
date = (TextView) itemView.findViewById(R.id.date);
tableLayout = (TableLayout)
itemView.findViewById(R.id.maintablelayout);
}
还有一个问题,有没有更好的方法可以在不使用任何库的情况下将 tableLayout 与 recycler View 一起使用?
谢谢..!
忽然笑
米琪卡哇伊
DIEA
相关分类