Reputation: 5259
Hello I want to do this: I am pulling data from a server and I need when for example pull out the number 0 the textview to ber red color, on any other case to be green color. I do not know if there is a way of placing something like an if statement in the xml file or somewhere else.
Upvotes: 0
Views: 606
Reputation: 641
You need to to first instantiate your text view like
TextView tv = (TextView)findViewById(R.id.idOfTextViewInXML);
Now you can perform change this text view as you please . For example
if(var==0)
tv.setText("VALUE IS ZERO");
else
tv.setBackgroundResource(R.drawable.icon);
This is the way you need to change the features of views dynamically . You can't really change the XML itself dynamically .
All this must be performed in the Java class .
Upvotes: 1
Reputation: 26971
When you parse your xml in your code, just add a if statement.
if(number == 0){
else{
//do something
}
Upvotes: 0
Reputation: 5892
Once u have data from sever in form of xml , parser the xml and process it (to check for your condition ).
Upvotes: 0