问题导航抽屉中每个可展开列表视图项目的不同图像
尝试了几乎所有参考文献,但我想我的数据源有点棘手。
请为每个列表标题使用图标建议方法或代码
示例:
image1 text1
image2 text2
image3 text3
imag4 text4
image5 text5
这是适配器的组视图
@Override
public View getGroupView(int listPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View v = convertView;
String group = null;
int id_res = 0;
String listTitle = (String) getGroup(listPosition);
if (convertView == null) {
convertView = mLayoutInflater.inflate(R.layout.list_group, null);
TextView listTitleTextView = (TextView) convertView
.findViewById(R.id.listTitle);
listTitleTextView.setTypeface(null, Typeface.BOLD);
listTitleTextView.setText(listTitle);
ImageView img=(ImageView) convertView.findViewById(R.id.image1); <--- adding image here
}
return convertView;
}
这是我的数据源
public class ExpandableListDataSource {
public static Map<String, List<String>> getData(Context context) {
HashMap<String, List<String>> expandableListData = new LinkedHashMap<>();
List<String> menu = Arrays.asList(context.getResources().getStringArray(R.array.menu));
List<String> home = Arrays.asList(context.getResources().getStringArray(R.array.home));
List<String> one= Arrays.asList(context.getResources().getStringArray(R.array.one));
List<String> two= Arrays.asList(context.getResources().getStringArray(R.array.two));
List<String> three= Arrays.asList(context.getResources().getStringArray(R.array.three));
List<String> four= Arrays.asList(context.getResources().getStringArray(R.array.four));
List<String> five= Arrays.asList(context.getResources().getStringArray(R.array.five));
List<String> six = Arrays.asList(context.getResources().getStringArray(R.array.six));
expandableListData.put(menu.get(0), home);
expandableListData.put(menu.get(1), one);
expandableListData.put(menu.get(2), two);
expandableListData.put(menu.get(3), three);
expandableListData.put(menu.get(4), four);
expandableListData.put(menu.get(5), five);
expandableListData.put(menu.get(6), six);
return expandableListData;
}
}