我是 Android 和一般编程的新手。我正在尝试用一些数据加载 RecyclerView。在调试模式下,直到最后,应用程序崩溃时,它才会显示错误。这里使用的主要数据是一个名为 Lettura 的实体,它是房间数据库的一部分。
在这里,我调用并使用一些数据填充视图:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vedi_letture_simple);
ArrayList<Lettura> letture = new ArrayList<>();
Date date = new Date(1989, 1, 1);
Lettura a = new Lettura("a", "b", "c", 14.5, date, 1);
letture.add(a);
RecyclerView recView = (RecyclerView) findViewById(R.id.lettura_recyclerview);
LetturaAdapter mlAdapter = new LetturaAdapter(this, letture); //made final
recView.setAdapter(mlAdapter);
// use a linear layout manager
LinearLayoutManagr lll = new LinearLayoutManager(this);
recView.setLayoutManager(lll);
这里是适配器类 LetturaAdapter.class
class LetturaAdapter extends RecyclerView.Adapter<LetturaAdapter.LetturaViewHolder> {
private ArrayList<Lettura> letture;
private LayoutInflater mInflater;
public LetturaAdapter(Context context, ArrayList<Lettura> lettura){
this.mInflater = LayoutInflater.from(context);
this.letture = lettura;
}
@Override
public void onBindViewHolder(LetturaViewHolder rigaHolded, int position) {
Lettura current;
current = letture.get(position);
TextView barT = hholded.barcodeItemView;
barT.setText(current.getBarcode());
TextView desT = hholded.descriptionItemView;
desT.setText(current.getDescription());
TextView priceT = hholded.priceItemView;
priceT.setText(current.getPrice().toString());
TextView dateT = hholded.dateItemView;
dateT.setText(current.getDate().toString());
TextView quanT = hholded.quantityItemView;
quanT.setText(current.getQuantity());
}
POPMUISE
温温酱
阿波罗的战车
相关分类