1
votes

Comment afficher plusieurs TextViews dans un élément de liste RecyclerView

J'utilise un ReyclerView et je souhaite afficher 3 TextViews dans chaque élément de la liste. Jusqu'à présent, j'ai réussi à afficher 3 TextViews mais sous forme de 3 éléments de liste différents.

Voici mon code d'adaptateur:

<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>

Et layout_item.xml:

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;
    }


1 commentaires

Mettez simplement 3 TextView dans votre layout_item ?


3 Réponses :


1
votes

ajoutez simplement deux textViews supplémentaires dans layout_item


4 commentaires

que se passe-t-il quand tu le fais


ce que vous voulez exactement, plus de texte Voir dans le recycleur ou dans le support


difficile à expliquer, il ne fonctionne tout simplement pas comme je le voulais


plus de texteVues dans le support dans think



0
votes

Utilisez la mise en page relative au lieu de la mise en page linéaire si vous souhaitez définir trois vues de texte. Il sera beaucoup plus facile de faire glisser et de déposer une vue de texte à partir de Design Platte où vous souhaitez définir ces vues de texte


0 commentaires

1
votes
    <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 

0 commentaires