简体   繁体   中英

call textview and imageview in recyclerview

hello I have made a layout of TextView(in it i've set a background image) and a simple TextView view and inflate both in adapter and showed them in a recycler view, i can change the TextView(with background) and TextView as my wish in different list of recyclerview but i also want to change the background of textview with its change in text.

this is arraylist where i entered two textview but i dont know where to enter background images

wordList.add(new Word("1", "What is neuron?"));
wordList.add(new Word("2", "What is brain?"));
wordList.add(new Word("3", "What is gala?"));
wordList.add(new Word("4", "What is accurd?"));

<TextView android:textColor="@android:color/white"
        android:gravity="center"
        android:id="@+id/circle"
        android:background="@drawable/teal"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="8dp"
        android:text="C"
        android:layout_centerVertical="true"/>
    <TextView
        android:textSize="20sp"
        android:id="@+id/prod_name"
        android:paddingLeft="8dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/circle"
        android:layout_centerVertical="true"/>

If you are getting background images locally from drawable resources, then you will have to modify your Word class like this

Class Word { 
       private String tv1;
       private String tv2;
       private Drawable backgroundImage;

           Word(String a, String b, Drawable c){
              tv1=a; 
              tv2=b;
              backgroundImage=c
           }
       }

now you can add images like this

wordList.add(new Word("1", "What is neuron?", 
getResources().getDrawable(R.drawable.your_img)));
wordList.add(new Word("2", "What is brain?", 
getResources().getDrawable(R.drawable.your_img)));
wordList.add(new Word("3", "What is 
gala?", getResources().getDrawable(R.drawable.your_img)));
wordList.add(new Word("4", "What is 
accurd?", getResources().getDrawable(R.drawable.your_img)));

Now you have the background images in your ArrayList. You can use them as you wish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM