I have subclassed ArrayAdapter to set the color of text to RED if the
string does not contain 100%, this has been added to a ListView. The
problem is that some of the rows show as red when they contain 100%.
Why would this happen?
/*
* Subclass of ArrayAdapter to change the color of the
* text to red if it is not 100%
*
*/
public class ScoringAdapter extends ArrayAdapter<String> {
private ArrayList<String> items;
public ScoringAdapter(Context context, int textViewResourceId,
ArrayList<String> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup
parent) {
try {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate
(android.R.layout.simple_list_item_1, null);
}
String item = items.get(position);
TextView tv = (TextView) v.findViewById
(android.R.id.text1);
tv.setText(item);
if(!item.contains("100%")) {
tv.setTextColor(Color.RED);
}
return v;
}
catch(Exception e) {
e.printStackTrace();
}
return null;
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en