Reputation: 93
I need to change the text color of some specific items of the listview.
lstdetails = (ListView) findViewById(R.id.lstdetails);
ListAdapter adapter = new SimpleAdapter(
Details.this, details_list,
R.layout.Details, new String[] {
"lecture_key", "date",
"total_lect_int", "attendance" },
new int[] { R.id.tvKey, R.id.tvdate,
R.id.tvtotallect, R.id.tvattendance });
lstdetails.setAdapter(adapter);
Text color needs to be changed on the basis of the value of R.id.tvattendance
The above snippet is in the onPostExecute function of the class extending AsyncTask
Upvotes: 0
Views: 67
Reputation: 29285
I think there is two option for you to accomplish it.
Normal Way : Using a custom adapter and customize each row as you wish. For this way, please take a look at here
Ugly Way! : Use mListView.getFirstVisiblePosition()
and mListView.getLastVisiblePosition()
as well as mListView.getChildAt(...)
to obtain a reference to that row and then customize it as you wish.
Upvotes: 0
Reputation: 1379
You need to implement custom adapter You can view the full implementation i did in this opensource project
private class listviewAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int value= listAdapter.get(position); // or whatever data type is your value
if (value==0){
//change color of the textview at runtime here
}else{
//or some other color
}
}
}
i am using this inside a fragment and it works perfectly
Upvotes: 0
Reputation:
You need to implement custom adapter, extend from BaseAdapter
class, and change color in getView
method
Upvotes: 3