How to turn text into image

2

In my application, I have a listView that displays the database information, I want when loading the listView the String of one of the TextViews is replaced by an image. According to the text presented, a different image will appear. Can you do that and what would it be like?

The code is just to represent what I want in the application because it does not work!

    switch (textView1.getText()) {
        case textView1.getText("carro") ;            
    textView1.setBackground(R.drawable.image1);  
            break;

        case textView2.getText("moto") ;
     textView2.setBackground(R.drawable.image2);
            break;

     case textView3.getText("caminhao") ;
     textView3.setBackground(R.drawable.image3);
            break;  
    
asked by anonymous 23.10.2015 / 21:30

1 answer

0

To place an image as a background of a TextView use the following code:

textView.setBackground(getResources().getDrawable(R.drawable.image));  

If you are using the API level 21 or higher use:

textView.setBackground(getResources().getDrawable(R.drawable.image, getTheme()));
    
24.10.2015 / 00:16