Hey, Is it possible to change the background of a specified ro开发者_Go百科w in an ExpandableListView? What I want is: 1st row blue, 2nd red, 3rd blue, 4th red..... Thanks
Yes this is possible, and you have to use custom adapter for your Expandable list view.
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
//......
//...... Your code for row view
//.....
//Now write here code for set colors for rows
if(childPosition % 2 == 0) {
convertView.setBackgroundColor("#0000FF"); // use this when you want to use hexa value of colors
} else {
convertView.setBackgroundColor("#FF0000"); // use this when you want to use hexa value of colors
}
//setBackgroundResource(android.R.color.transparent); // use this for predefined colors at place of setBackground
return convertView;
}
Read this article, here example and source code also available.
You might want to check out this thread: Android ExpandableListView.
There is a working sample with the functionality you want (colorize the rows based on the data they hold).
Of course. You will simply need to manually set the background on the views as you create or recreate them. Do this in the adapter in the method
getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
Based on the group and child position
精彩评论