Issue with custom gridview Android Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Issue with custom gridview Android without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have developed an app in which I display data in Gridview. All data comes from local storage. I am able to display each data correctly and there are no issues with it. But when I have scroll the Gridview and goto the bottom and getback to Top,it changes position. And sometimes when I scroll down and getback to Top, a blank screen appears on screen;no data found at all!

So I thought that there is issue with getView(). I am unable to figure out the problem

Code of getView():

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder viewholder;
    // LayoutInflater inflator = activit.getLayoutInflater();
    if(convertView == null) {
        // recycled view is null so create it.
        viewholder = new ViewHolder();
        convertView = inflator.inflate(R.layout.gridviewrow, null);
        viewholder.imgvGridicon = (ImageView) convertView.findViewById(;
        viewholder.txtGridItemlabel = (TextView) convertView.findViewById(;
    } else {
        viewholder = (ViewHolder) convertView.getTag();      
    if ((lstpinfo.get(position).appname.toString()) != null) {
    return convertView;

Update:: Intitalize of inflater::

private LayoutInflater inflator;

     private ArrayList<PInfo> lstpinfo = new ArrayList<PInfo>();
     public GridViewAdapter(Context cntx, ArrayList<PInfo> lstpinfo) {

            activit = cntx;
            inflator = LayoutInflater.from(cntx);
            this.lstpinfo = lstpinfo;



You have to set your view height with fixed value. There’s a scrolling bug in android gridview with different heights. Please see this for reference.

We are here to answer your question about Issue with custom gridview Android - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji