I noob in android and need help, and I have an online xml, I used this example to parse. example
But do not know how to add color to the content "Var" depending on the value, if higher than zero, this is green and if it is less than zero red.
I noob in android and need help, and I have an online xml, I used this example to parse. example
But do not know how to add color to the content "Var" depending on the value, if higher than zero, this is green and if it is less than zero red.
Assuming this is the tutorial you've referring to http://www.jondev.net/articles/Android_XML_SAX_Parser_Example then i would assume that you've solved how to get the data into the listview already?
If you've used a customListAdapter i.e. as in this example http://jnastase.alner.net/archive/2010/12/19/custom-android-listadapter.aspx then you will need to add an additional step in the getView() method to customise the colour of your listitem view. For example, you could change the background colour or the text colour.
public View getView(int position, View convertView, ViewGroup parent) {
....
TextView mytext = findViewById(R.id.myText);
int yourVar = getItem(position).var;
if(yourVar > 0)
{
mytext.setTextColor(0x0000FF);
}else{
mytext.setTextColor(0xFF0000);
}
}
This assumes a certain amount, for example that your using a custom list adapter with your own layout.
Amendment. If this was a list of text in a textview, then you could try formatting it with html, for example this question shows how to colour text Change text color of one word in a TextView
String someText1 = "<font color='#FF0000'>this is red text</font>";
String someText2 = "Standard text"
yourTextView.setText(Html.fromHtml(someText1 + someText2));
This doesn't however completely answer your question as you will need to accomplish the following steps.
You could try regular expressions, or splitting the string to an array. Afraid i don't know this off the top of my head.