I have an expandable list in my application. In group view each element has an image in its left side. for this i took an xml for group row with an image view and textview inside a relative layout.
In my custom adapter class, am adding those text and images. text coming from database. and for image am giving drawable name. Following is my adapter class.
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if(convertView==null){
LayoutInflater vi = LayoutInflater.from(context);
convertView = vi.inflate(R.layout.event_row, null);
}
GroupEvent event = eventlist[groupPosition];
setEventTitle(convertView,event.getEvent());
setEventIcon(convertView,event.getEvent_icon(), event.getEvent());
setDivider(convertView,groupPosition);
return convertView;
}
private void setEventTitle(View convertView, String title) {
// TODO Auto-generated method stub
TextView event_title_field = (TextView) convertView.findViewById(R.id.event_name_field);
event_title_field.setText(title);
}
private void setEventIcon(View convertView, int event_icon, String title) {
// TODO Auto-generated method stub
ImageView event_logo = (ImageView) convertView.findViewById(R.id.event_row_image);
title = String.format( "%s%s",Character.toLowerCase(title.charAt(0)),title.substring(1));
Log.d("Log","drawable image name "+ title);
event_logo.setImageResource(context.getResources().getIdentifier(title, "drawable", "com.eteam.ito.history"));
}
It is working fine. But it is not dynamic one and for all rows same image will adding. The drawable image name and the list element text are same. How to give drawable address by using its title?
See you can add dynamically like this