From https://developer.android.com/preview/material/ui-widgets.html
(来自https://developer.android.com/preview/material/ui-widgets.html)
When we create RecyclerView.Adapter
we have to specify ViewHolder
that will bind with the adapter.
(创建RecyclerView.Adapter
,必须指定将与适配器绑定的ViewHolder
。)
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private String[] mDataset;
public MyAdapter(String[] myDataset) {
mDataset = myDataset;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView mTextView;
public ViewHolder(TextView v) {
super(v);
mTextView = v;
}
}
@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.some_layout, parent, false);
//findViewById...
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mTextView.setText(mDataset[position]);
}
@Override
public int getItemCount() {
return mDataset.length;
}
}
So, is it possible to create RecyclerView
with multiple view types?
(因此,是否可以创建具有多种视图类型的RecyclerView
?)
ask by Pongpat translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…