How to Add Image in Expandable List in Parent in Android

how to add images to the expandable list view for the parent?

Still not sure what is imagehader but to set image in expandablelistview header you should do something like this:

@Override
public View getGroupView(int listPosition, boolean isExpanded,
View convertView, ViewGroup parent) {

if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.your_layout, null);
}

ImageView imageheader = (ImageView) convertView.findViewById(R.id.imageheader);
return convertView;
}

Android Change image on click, custom expandable list adapter

In your custom adapter in the getGroupView() do this:

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View view,
ViewGroup parent) {

ImageView img_selection=(ImageView) view.findViewById(R.id.img_selection);
int imageResourceId = isExpanded ? R.drawable.group_closed
: R.drawable.group_open;
img_selection.setImageResource(imageResourceId);
}

Change expandable listview group image onCreate and from child

Nevermind, I got it working. The data source for my list view was always updated when I clicked a parent or child. The problem is the list wasn't refreshing. I had something similar to fix a few days ago and trying .notifyDataSetChanged() didn't work so I didn't use it for this. It turns out however, that this works. Thanks anyway @m0skit0. Still not sure however, why the NPE. I'll try to figure it out.



Related Topics



Leave a reply



Submit