Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7196899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:52:00+00:00 2026-05-28T20:52:00+00:00

I’m trying to use a GridView with an ImageView and a TextView inside each

  • 0

I’m trying to use a GridView with an ImageView and a TextView inside each cell. So i created the cell layout, the grid layout, the imageAdapter and the main activity, of course, but i keep getting the following problem:

When i try this on the emulator, the initial images and captions are shown correctly but as soon as i scroll down, a few of the items start to mess up and keep changing and even duplicating some times.

I’m using 2 parallel arrays (images and caption). I tried using the Log.v function to find out which indexes and images were being shown when the getView was called but only the initial ones (which can be seen without scrolling) are assigned correctly.

I got to solve the problem by generating the view over and over but that’s obviously not the right way.

Here are the files I’m using:

Grid Cell:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/GridItem"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:gravity="center_horizontal">

   <ImageView android:id="@+id/grid_item_image"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
   </ImageView>

   <TextView android:id="@+id/grid_item_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView"
      android:gravity="center_horizontal"
      android:textColor="#FFFFFF">
   </TextView>

</LinearLayout>

GridView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:gravity="center_vertical"
        android:text="@string/txtMenu"
        />
    <GridView
        android:id="@+id/grdMenu"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="50dp"
        android:gravity="center"
        android:padding="10dp"
        android:horizontalSpacing="10dp"
        android:verticalSpacing="10dp"
        android:numColumns="3" >
    </GridView>

</RelativeLayout>

GridActivity: (The only implemented method)

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.menu);

    GridView gridview = (GridView) findViewById(R.id.grdMenu);
    gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Toast.makeText(getApplicationContext(), "" + position, Toast.LENGTH_SHORT).show();
        }
    });
}

ImageAdapter:

public class ImageAdapter extends BaseAdapter {

    private Context mContext;
    private Integer[] mThumbIds = {R.drawable.potencia32x32,R.drawable.detalle_cuenta32x32,R.drawable.solicitud32x32,R.drawable.agregar32x32,R.drawable.cyr_32x32,
            R.drawable.usuarios,R.drawable.cambio_med64x64,R.drawable.cobranza_ex64x64,R.drawable.convenio_pagos64x64,R.drawable.copiabf64x64,
            R.drawable.info_cliente64x64,R.drawable.mant_exp64x64,R.drawable.ordenes64x64,R.drawable.reembolsos64x64,R.drawable.seguro64x64,R.drawable.solicitudes64x64,
            R.drawable.suministro64x64

    };
    private String[] Caption = {"Consumo","Facturaciones","Solicitudes","Pagos","Cortes y Rcnx","Datos Generales","Cambios de Medidores","Cobranza Externa","Convenio Pagos","Copia Fac. o Bol.",
            "Info. Cliente","Mant. Expediente","Consulta Ordenes","Historia Reembolsos","Seguros","Solicitudes","Caracteristicas Suministro"

    };
    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return mThumbIds.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }


    public View getView(int position, View convertView, ViewGroup parent) {


        View myView  = null;

        if(convertView==null)
        {
            LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            myView = li.inflate(R.layout.grdmenu_cell, null);

            TextView tv = (TextView) myView.findViewById(R.id.grid_item_text);
            Log.v("D:<",String.valueOf(Caption.length) +" y: "+ String.valueOf(position));
            tv.setText(Caption[position]);


            ImageView iv = (ImageView) myView.findViewById(R.id.grid_item_image);
            Log.v("D:<",String.valueOf(mThumbIds.length) +" y: "+ String.valueOf(position));
            iv.setImageResource(mThumbIds[position]);
        }
        else
        {
            myView = convertView;
        }

        return myView;
    }

}

This is my very first question so if I committed any mistakes, please tell me. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:52:01+00:00Added an answer on May 28, 2026 at 8:52 pm

    I think the error is in your getView of your Adapter. ConvertView won’t hold on to your resources accessed through findViewById() and whatnot, only the inflated view. Try changing it to something like this:

    public View getView(int position, View convertView, ViewGroup parent) {
    
    
        View myView  = null;
    
        if(convertView==null)
        {
            LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            myView = li.inflate(R.layout.grdmenu_cell, null);
        }else{
            myView = convertView;
        }
    
    
        TextView tv = (TextView) myView.findViewById(R.id.grid_item_text);
        Log.v("D:<",String.valueOf(Caption.length) +" y: "+ String.valueOf(position));
        tv.setText(Caption[position]);
    
        ImageView iv = (ImageView) myView.findViewById(R.id.grid_item_image);
        Log.v("D:<",String.valueOf(mThumbIds.length) +" y: "+ String.valueOf(position));
        iv.setImageResource(mThumbIds[position]);
    
        return myView;
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.