sparrow sparrow - 4 months ago 7x
Android Question

Please help solve this listview problem

i have this 3 lines of code which i use to hold the state of items in my listview wjen scrolling, but my problem is, the last line of code only gets executed. could you please help me solve this. this is the code block:

holder.viewName.setTextColor((priority.equals("Low")? Color.BLUE: Color.GRAY ) );
holder.viewName.setTextColor((priority.equals("Medium")? Color.GREEN: Color.GRAY ) );
holder.viewName.setTextColor((priority.equals("High")? Color.RED: Color.GRAY ) ); // items in this state condition only gets executed in the listview, the rest are ignored and set to gray.

is there a way i can join the code logic together, so that all 3 conditions can be called?.. thank you


All 3 lines get executed, but you're always overriding the text color with the next line. Use a condition instead:

if (priority.equals("Low")) {
} else if (priority.equals("Medium")) {
} else if (priority.equals("High")) {
} else {

Edit: Switch statements for strings is not yet availalbe in Java right?