我有基本的知识expandablelistview
,想知道如何让每个孩子和每个小组都有不同的图像。我需要以某种方式修改可扩展列表适配器吗?任何帮助,想法,评论将不胜感激。谢谢 :)
主要活动:
public class MainActivity extends Activity{
.....
public static final Integer[] images = {
R.drawable.vegetables,
R.drawable.fruits,
R.drawable.drinks,
R.drawable.dessert
};
@Override
protected void onCreate(Bundle savedInstanceState) {
}
}
我的适配器
public class ExpandableListAdapter extends BaseExpandableListAdapter{
@Override
public View getChildView(int groupPosition,final int childPosition, boolean isLastChild, View convertView,
ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
ImageView imgListChild= (ImageView) convertView
.findViewById(R.id.IV_childImage);
// I could store images somehow in two dimensional array and then depending on that draw their reference id.
// imgListChild.setImageResource();
return convertView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
ImageView imgListGroup= (ImageView) convertView
.findViewById(R.id.IV_group);
imgListGroup.setImageResource(MainActivity.images[groupPosition]);
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}