Skip to content Skip to sidebar Skip to footer

Gridview Not Displaying In Fragment

Im trying to follow this Gridview with Auto resize image example and tried it in a Fragment. Here is the code: FragmentOne public class FragmentOne extends Fragment{ GridView grid

Solution 1:

There may be problem in getView method. It looks like a false implementation of view holder pattern.

We can try without pattern.

Can you try this for being sure to identify problem.

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
    convertView = inflater.inflate(R.layout.gridviewitem, parent, false);

    ImageViewimage= (ImageView) convertView.findViewById(R.id.gvItemImage);
    TextViewtext= (TextView) convertView.findViewById(R.id.gvItemText);

    image.setImageResource(getItem(position).drawableId);
    text.setText(getItem(position).name);

    return convertView;
}


staticclassItem
{
    final String name;
    finalint drawableId;

    Item(String name, int drawableId)
    {
        this.name = name;
        this.drawableId = drawableId;
    }
}

Post a Comment for "Gridview Not Displaying In Fragment"