I have a simpleAdapter that get data from json and put it in a listview look like this:
adapter = new SimpleAdapter(
// Updating listview
getActivity(), arrMeetings,
R.layout.meeting_item, new String[] {mtTAG_MEETINGNAME, mtTAG_DATE, mtTAG_TIME, mtTAG_LOCATION, mtTAG_MEETINGSTATUS},
new int[] { R.id.txtTitleMeeting, R.id.txtDatetime, R.id.txtTime, R.id.txtLocation, R.id.txtStatusMeeting});
I want to set color for textview txtStatusMeeting
and the color decide by data from json: red color for Done
and blue color for Incoming
.
Is there anyway to do that without a custom adapter?
Update
I done it for now. Thank you guys. The final code below:
adapter = new SimpleAdapter(
// Updating listview
getActivity(), arrMeetings,
R.layout.meeting_item, new String[] {mtTAG_MEETINGNAME, mtTAG_DATE, mtTAG_TIME, mtTAG_LOCATION, mtTAG_MEETINGSTATUS},
new int[] { R.id.txtTitleMeeting, R.id.txtDatetime, R.id.txtTime, R.id.txtLocation, R.id.txtStatusMeeting}){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
for(int i=0;i<arrMeetings.size();i++){
if(v == null){
LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=vi.inflate(R.layout.meeting_item, null);
}
TextView txtTitleMeeting = (TextView) v.findViewById(R.id.txtTitleMeeting);
TextView txtDatetime = (TextView) v.findViewById(R.id.txtDatetime);
TextView txtTime = (TextView) v.findViewById(R.id.txtTime);
TextView txtLocation = (TextView) v.findViewById(R.id.txtLocation);
TextView txtStatusMeeting = (TextView) v.findViewById(R.id.txtStatusMeeting);
txtTitleMeeting.setText(arrMeetings.get(position).get(mtTAG_MEETINGNAME));
txtDatetime.setText(arrMeetings.get(position).get(mtTAG_DATE));
txtTime.setText(arrMeetings.get(position).get(mtTAG_TIME));
txtLocation.setText(arrMeetings.get(position).get(mtTAG_LOCATION));
if(arrMeetings.get(position).get(mtTAG_MEETINGSTATUS).equals("Today")){
txtStatusMeeting.setText(arrMeetings.get(position).get(mtTAG_MEETINGSTATUS));
txtStatusMeeting.setTextColor(getActivity().getResources().getColor(R.color.Today));
}else if(arrMeetings.get(position).get(mtTAG_MEETINGSTATUS).equals("Incoming")){
txtStatusMeeting.setText(arrMeetings.get(position).get(mtTAG_MEETINGSTATUS));
txtStatusMeeting.setTextColor(getActivity().getResources().getColor(R.color.Incoming));
}else if(arrMeetings.get(position).get(mtTAG_MEETINGSTATUS).equals("Done")){
txtStatusMeeting.setText(arrMeetings.get(position).get(mtTAG_MEETINGSTATUS));
txtStatusMeeting.setTextColor(getActivity().getResources().getColor(R.color.Done));
}
}
return v;
}
};