I have this layout in which I have a listview. The content of list is defined in another layout.I have text views inside this layout and I want to dynamically change the color of the text view depending on some condition(like simple if else).Please let me know how to do this.
Here is my code-:
package com.example.fastcashier;
public class Myperwallet extends ListActivity {
ImageView upload,more,logout,send,history;
String userpin;
TextView fname,lname,cur,bal,pin;
String firstname,lastname,curr,balance,pin1,deb;
static final String baseURL = "http://192.168.0.2:10095/androidxml/permywallet.php?usenam=";
static final String KEY_ITEM = "item";
static final String KEY_DATE = "date";
static final String KEY_DEB = "debit";
static final String KEY_TID = "transactionID";
static final String KEY_AMO = "amount";
static final String KEY_CAT = "category";
static final String KEY_FNM = "firstname";
static final String KEY_LNM = "lastname";
static final String KEY_PIN = "pin";
static final String KEY_BAL = "balance";
static final String KEY_CUR = "currency";
static final String KEY_FEES = "fees";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myperwallet);
Bundle gotuser= getIntent().getExtras();
userpin= gotuser.getString("username");
StringBuilder URL= new StringBuilder(baseURL);
URL.append(userpin);
String fullUrl =URL.toString();
Log.i("log_tag", "new url " + fullUrl);
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
inboxParser parser = new inboxParser();
String xml = parser.getXmlFromUrl(fullUrl);
Document doc = parser.getDomElement(xml);
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
for (int i = 0; i < nl.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
firstname = parser.getValue(e, KEY_FNM);
lastname = parser.getValue(e, KEY_LNM);
curr = parser.getValue(e, KEY_CUR);
balance= parser.getValue(e, KEY_BAL);
pin1= parser.getValue(e, KEY_PIN);
deb = parser.getValue(e, KEY_DEB);
map.put(KEY_DATE, parser.getValue(e, KEY_DATE));
map.put(KEY_DEB, parser.getValue(e, KEY_DEB));
map.put(KEY_TID, parser.getValue(e, KEY_TID));
map.put(KEY_AMO, parser.getValue(e, KEY_AMO));
map.put(KEY_CAT, parser.getValue(e, KEY_CAT));
map.put(KEY_FNM, parser.getValue(e, KEY_FNM));
map.put(KEY_LNM, parser.getValue(e, KEY_LNM));
map.put(KEY_CUR, parser.getValue(e, KEY_CUR));
map.put(KEY_PIN, parser.getValue(e, KEY_PIN));
map.put(KEY_BAL, parser.getValue(e, KEY_BAL));
map.put(KEY_FEES, parser.getValue(e, KEY_FEES));
Log.i("log_tag", "debit " + deb);
menuItems.add(map);
}
fname.setText(firstname);
lname.setText(lastname);
cur.setText(curr);
bal.setText(balance);
pin.setText(pin1);
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.recentlist,
new String[] { KEY_CAT, KEY_DATE, KEY_TID, KEY_AMO, KEY_DEB,KEY_CUR,KEY_BAL,KEY_FEES}, new int[] {
R.id.textView1,R.id.textView2, R.id.textView3, R.id.textView4,R.id.textView5,R.id.textView7,R.id.textView6,R.id.textView8});
setListAdapter(adapter);
}
}