The problem is that the elements of the submenu of the ExpandableListView are loaded as they appear on the screen, and when they are no longer displayed on the screen they lose their data because when I go back to where they are located they are reloaded.
When they only have pure text you do not notice the difference, but the problem is when they have an image, since it looks like it is loading, and sometimes it even shows a wrong image for a short time until it is updated again.
Is there any way to make this data static?
I attach the code of my Adapter.
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private List<ExpandedMenuModel> mListDataHeader; // header titles
// child data in format of header title, child title
private HashMap<ExpandedMenuModel, List<SubmenuModel>> mListDataChild;
ExpandableListView expandList;
public ExpandableListAdapter(Context context, List<ExpandedMenuModel> listDataHeader,
HashMap<ExpandedMenuModel, List<SubmenuModel>> listChildData,
ExpandableListView mView) {
this.mContext = context;
this.mListDataHeader = listDataHeader;
this.mListDataChild = listChildData;
this.expandList = mView;
}
@Override
public int getGroupCount() {
return this.mListDataHeader.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return this.mListDataChild.get(this.mListDataHeader.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return this.mListDataHeader.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return this.mListDataChild.get(this.mListDataHeader.get(groupPosition))
.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
//aqui se edita el menu
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ExpandedMenuModel headerTitle = (ExpandedMenuModel) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.listheader, null);
}
TextView lblListHeader = convertView.findViewById(R.id.menuText);
ImageView headerIcon = convertView.findViewById(R.id.iconimage);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle.getIconName());
headerIcon.setImageResource(headerTitle.getIconImg());
return convertView;
}
//aqui se editan los submenus
@Override
public View getChildView(int groupPosition,final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
final SubmenuModel childText = (SubmenuModel) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_submenu, null);
}
TextView txtListChild = convertView.findViewById(R.id.submenu);
txtListChild.setText(childText.getText());
CircleImageView imageSubmenu = convertView.findViewById(R.id.imageSubmenu);
if(childText.getTypeSubmenu() == SubmenuModel.TYPE_PARTICIPANT) {
new DownloadImageTask(imageSubmenu)
.execute(childText.getUrlimg());
imageSubmenu.setVisibility(View.VISIBLE);
} else {
imageSubmenu.setVisibility(View.GONE);
}
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}