I have a problem with the fact that I am implementing an ExpandableListView with a grid view as a child of the same parent. GridView has 46 images. Therefore, when we open the first parent, it shows a grid with more than 46 images with a slot of 46 images. This means one slot out of 46 images, then another 46 images are shown, which are shown again below, and then another and then another. The tool is repeated many times in one layout. I could not find the source of the problem, so I could not solve it. Please offer me some solution regarding the same.
Code (expandable list):
public class ExpResearchListAdapter extends BaseExpandableListAdapter {
Context context;
GridView label;
TextView groupText;
ImageView groupImg;
ArrayList<String> groups = new ArrayList<String>();
ArrayList<Integer> groupImage = new ArrayList<Integer>();
ArrayList<Integer> childElement = new ArrayList<Integer>();
private Integer[][] children = {
{ R.drawable.icon_1, R.drawable.icon_2, R.drawable.icon_3, R.drawable.icon_4, R.drawable.icon_5, R.drawable.icon_6, R.drawable.icon_7, R.drawable.icon_8, R.drawable.icon_9,
R.drawable.icon_10, R.drawable.icon_11, R.drawable.icon_12, R.drawable.icon_13, R.drawable.icon_14, R.drawable.icon_15, R.drawable.icon_16, R.drawable.icon_17, R.drawable.icon_18,
R.drawable.icon_19, R.drawable.icon_20, R.drawable.icon_21, R.drawable.icon_22, R.drawable.icon_23, R.drawable.icon_24, R.drawable.icon_25, R.drawable.icon_26, R.drawable.icon_27,
R.drawable.icon_28, R.drawable.icon_29, R.drawable.icon_30, R.drawable.icon_31, R.drawable.icon_32, R.drawable.icon_33, R.drawable.icon_34, R.drawable.icon_35, R.drawable.icon_36,
R.drawable.icon_37, R.drawable.icon_38, R.drawable.icon_39, R.drawable.icon_40, R.drawable.icon_41, R.drawable.icon_42, R.drawable.icon_43, R.drawable.icon_44, R.drawable.icon_45,
R.drawable.icon_46}
};
LinearLayout linear;
public ExpResearchListAdapter(Context context, ArrayList<String> groups, ArrayList<Integer> groupImage, ArrayList<Integer> childElement, LinearLayout linear)
{
this.context=context;
this.groups = groups;
this.groupImage = groupImage;
this.childElement = childElement;
this.linear = linear;
}
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
int i = 0;
try {
i = children[groupPosition].length;
} catch (Exception e) {
}
return i;
}
public TextView getGenericView() {
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView textView = new TextView(context);
textView.setLayoutParams(lp);
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
textView.setPadding(36, 0, 0, 0);
return textView;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if(convertView==null)
{
LayoutInflater inflater = LayoutInflater.from(context);
convertView = (View) inflater.inflate(R.layout.brand_research_grid, null);
label = (GridView) convertView.findViewById(R.id.gv_ResearchList_Child);
label.setAdapter(new GridAdapter(context, children));
label.setCacheColorHint(Color.WHITE);
final int spacingDp = 10;
final int colWidthDp = 50;
final int rowHeightDp = 107;
final float COL_WIDTH = context.getResources().getDisplayMetrics().density * colWidthDp;
final float ROW_HEIGHT = context.getResources().getDisplayMetrics().density * rowHeightDp;
final float SPACING = context.getResources().getDisplayMetrics().density * spacingDp;
System.out.println("===================================RowHeight"+ROW_HEIGHT);
System.out.println("===================================RowHeightDP"+rowHeightDp);
final int colCount = (int)Math.floor((linear.getWidth() - (2 * SPACING)) / (COL_WIDTH + SPACING));
final int rowCount = 16;
final int GRID_HEIGHT = Math.round(rowCount * (ROW_HEIGHT + SPACING));
System.out.println("===================================GHieght"+GRID_HEIGHT);
System.out.println("===================================colCount"+colCount);
System.out.println("===================================rowCount"+rowCount);
label.getLayoutParams().height = GRID_HEIGHT;
}
return convertView;
}
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
public int getGroupCount() {
return groups.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String group = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(
R.layout.research_list_exp_group, null);
groupText = (TextView) convertView
.findViewById(R.id.tv_ResearchList_ExpParentElement);
groupImg = (ImageView) convertView
.findViewById(R.id.img_ResearchList_GroupParentImage);
}
groupText.setText(group);
groupImg.setImageResource(groupImage.get(groupPosition));
return convertView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
GridAdapter:
public class GridAdapter extends BaseAdapter{
public Context context;
private LayoutInflater mInflater;
Integer[][] childElements;
ImageView imgGridItem;
public GridAdapter(Context context, Integer[][] childElements)
{
this.context = context;
this.childElements = childElements;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return childElements.length;
}
@Override
public Object getItem(int arg0) {
return arg0;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.grid_item, null);
holder = new ViewHolder();
imgGridItem = (ImageView)convertView.findViewById(R.id.img_GridItem);
}
imgGridItem.setImageResource(childElements[position][0]);
return convertView;
}
class ViewHolder {
private ImageView imgGridItem;
}
}
Thanks in advance.