Reputation: 29
I'm using a ReyclerView and I want to display 3 TextViews in each list item. so far I managed to display 3 TextViews but as 3 different list items.
Here's my adapter code:
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;
}
And 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>
Upvotes: 1
Views: 117
Reputation: 370
<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/text_view_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"/>
<TextView
android:id="@+id/text_view_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"/>
<TextView
android:id="@+id/text_view_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"/>
</LinearLayout>
// If you want your textviews next to each other use android:orientation="horizontal" in LinearLayout or if you want your textviews one below the other use android:orientation="vertical" and this will in one view
Upvotes: 1
Reputation: 145
Use Relative layout instead of Linear layout if you want to set three Textviews .It will be much easier you can drag and drop textview from design Platte where you want to set those Textviews
Upvotes: 0