【发布时间】:2020-03-18 11:56:14
【问题描述】:
我正在使用 ReyclerView,我想在每个列表项中显示 3 个 TextView。 到目前为止,我设法将 3 个 TextViews 显示为 3 个不同的列表项。
这是我的适配器代码:
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder> {
private String[] mDataset;
public static class MyViewHolder extends RecyclerView.ViewHolder {
public TextView textView;
public MyViewHolder(View v) {
super(v);
textView = v.findViewById(R.id.recycler_view_item);
}
}
public CustomAdapter(String[] myDataset) {
mDataset = myDataset;
}
@Override
public CustomAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_item, parent, false);
MyViewHolder vh = new MyViewHolder(v);
return vh;
}
还有layout_item.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="15dp">
<TextView
android:id="@+id/recycler_view_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"/>
</LinearLayout>
【问题讨论】:
-
只需将 3 个
TextViews 放入您的layout_item?
标签: java android xml android-recyclerview