Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid gridview : error while displaying large number of images
    primarykey
    data
    text
    <p>I have a grid view which is populated using a custom ImageAdapter class extending BaseAdapter. The images are dynamically loaded from a particular folder in the SD card. I have named the images according to their postition (1.png, 2.png etc.). I have also set an <code>OnClickListener</code> for the grid items: an audio file with the same name as the image is played from the SD card. </p> <p>It works well when the number of images is less and fits on a screen.</p> <p>But when the number is large and the images doesn't fit on a screen, the next set of rows displayed by scrolling the screen downwards is mostly repetition of images from the first few rows rather than the images at the corresponding position.</p> <p>I find from the logcat that the <code>getView()</code> function of the adapter class gets called initially only for the images which are visible on the screen and while scrolling downwards, its not being called properly for further positions</p> <p>Also sometimes the entire set of images gets re-arranged. Should I do anything different from the basic implementation of grid view for properly displaying large number of images? Is there anything else I must be taking care of?</p> <p>EDIT - CODE</p> <p>I'm setting each tab using</p> <pre><code>tabGrid[i].setAdapter(new ImageAdapter(this,i)); </code></pre> <p>This is the image adapter class</p> <pre><code>@Override public int getCount() { // fileNames is a string array containing the image file names : 1.png, 2.png etc return fileNames.length; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { // I did not use this function return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View v; if(convertView==null) { LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.grid_image, null); ImageView iv = (ImageView)v.findViewById(R.id.icon_image); String bitmapFileName = fileNames[position]; Bitmap bmp =(Bitmap)BitmapFactory.decodeFile(dir.getPath() + "/" + bitmapFileName);a iv.setImageBitmap(bmp); } else { v = convertView; } return v; } </code></pre> <p>Does the <code>getItem()</code> and <code>getItemId()</code> functions matter? The directories and file names are all valid.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload