我正在使用可扩展列表适配器来放置具有 3 个组的视图,每个组有 4 个子子项,当前每个组具有相同的图标图像。我需要将 3 个不同的图像放到三个组中。如何将其放入 android 中。请帮助。
问问题
111 次
1 回答
0
我认为你已经在你的一类中扩展了 BaseExpandableListAdapter 。因为你将有一种方法
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
View row = convertView;
MyHolder hldr = null;
try{
if(row==null){
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.disp_lib_group_row, null);
hldr = new MyHolder();
hldr.txtv1 = (TextView) row.findViewById(R.id.txtGrp);
hldr.imgv1 = (ImageView) row.findViewById(R.id.imgGrp);
row.setTag(hldr);
}
else{
hldr=(MyHolder)row.getTag();
}
hldr.txtv1.setText(getGroup(groupPosition).toString());
EDIT EDIT EDIT EDIT EDIT
System.out.println("Group Position: "+groupPosition);
// here you will get groupPosition, like 0/1/2/3
// just check it by if condition and
// set needed image in followin line code
if(groupPosition == 0)
hldr.imgv1.setImageResource(R.drawable.img0);
if(groupPosition == 1)
hldr.imgv1.setImageResource(R.drawable.img1);
...... Check 2, 3 ......
EDIT OVER OVER
}
}catch(Exception e){System.out.println("Error: \n");e.printStackTrace();}
return row;
}
于 2012-07-13T18:00:53.997 回答