I’m trying to use gridview to make some menu using this tutorial.
Unfortunetly, when I’m scrolling my menu, positions of menu items goes randomly.
I’m using .xml to show image and title.
BTW: Is there any way to sort GridView?
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
String tmp = menuItems[position];
gridView = new View(context);
gridView = inflater.inflate(R.layout.menuitem, null);
TextView label = (TextView) gridView.findViewById(R.id.menuitem_label);
label.setText(context.getString(context.getResources().getIdentifier("string/txt_"+tmp, null, context.getPackageName())));
ImageView img = (ImageView) gridView.findViewById(R.id.menuitem_image);
SVG svg_img = SVGParser.getSVGFromResource(context.getResources(), context.getResources().getIdentifier("raw/"+tmp, null, context.getPackageName()));
if (svg_img != null)
img.setImageDrawable(svg_img.createPictureDrawable());
} else {
gridView = (View) convertView;
}
return gridView;
}
Please study more about gridviews and recycling. There are bunch of tutorials in net as well as here in stack overflow
I just recreate your codes. I havent tried it yet