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 Textview to be replaced by an image. According to the displayed text, a different image will appear. It has how to do this and how it would be?
The code is only to represent what I want in the application because it doesn’t 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;
The code I’m trying to use is this, but it’s going wrong
– Raphael de souza
What’s the mistake ?
– ramaral
By calling the
setTvImage();
the application gives error and closes, Talve I’m making the call in a wrong location or my code that doesn’t even work!– Raphael de souza
Not knowing what the error is hard to help. You got the reference to Textview tvImage:
tvImage = (TextView)findViewById(....);
?– ramaral
Yes, I got the reference for the textView tvImage.
– Raphael de souza
Could the problem be because you’re using the if instead of the switch case?
– Raphael de souza
Without you posting the log error is impossible to know where the problem is.
– ramaral
I just posted the log
– Raphael de souza
The error says tvImage is null. With the latest developments this question is becoming a totally different one. This is out of the way of the website. The correct thing to do is to ask this question as it was at the beginning (reverse it) and do another one with the code and the log. Consider voting/accepting the answer if you deem it appropriate to do so
– ramaral