Dynamic Xml, Changing Text
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
Solution 1:
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 .
Solution 2:
Once u have data from sever in form of xml , parser the xml and process it (to check for your condition ).
Solution 3:
When you parse your xml in your code, just add a if statement.
if(number == 0){
else{
//do something
}
Post a Comment for "Dynamic Xml, Changing Text"