android - Set colour of text in a listview -
i have simple listview has values defined in 2 string arrays, , i'm looking have colour of text in listview change if equals value.
here i've tried, isn't working
///rest of oncreate above var = new string[]{"text", "words", "other"}; val = new string[]{"t", "w", "o"}; preparelist(); ///rest of oncreate go here... } private void preparelist(){ thelist = new arraylist<hashmap<string, string>>(); (int = 0; < var.length; i++) { map2 = new hashmap<string, string>(); map2.put("one", var[i]); map2.put("two", val[i]); thelist.add(map2); } try { adapter = new simpleadapter(this, thelist, r.layout.row, new string[] {"one", "two" }, new int[] { r.id.one, r.id.two }); list.setadapter(adapter); setlistviewheightbasedonchildren(list); } catch (exception e) { } textview t = (textview)findviewbyid(r.id.one); if(t.equals("words")){ t.settextcolor(color.blue); } } basically in example, want in list equals "words" changed blue, if statement checks for, doesn't work
you need define custom adapter class extending simpleadapter class , re-implement getview() method. inside getview(), put condition text color.
a example of extending simpleadapter here
Comments
Post a Comment