Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a quick fix which should be better.</p> <pre><code>@Override public String getItem(int position) { return fileNames[position]; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v; if(convertView==null) { LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.grid_image, parent, false); } else { v = convertView; } ImageView iv = (ImageView)v.findViewById(R.id.icon_image); String bitmapFileName = getItem(position); Bitmap bmp =(Bitmap)BitmapFactory.decodeFile(dir.getPath() + "/" + bitmapFileName);a iv.setImageBitmap(bmp); return v; } </code></pre> <ol> <li>I filled getItem, it's not 100% needed but it's always better to have it. The rest of your adapter code can then rely on it</li> <li>The item id should be different for every entry, you could either use getItem(position).hashCode() (might be slower) or just return position (which I did here).</li> <li>The getView method is a bit more tricky. The idea is that if the convertView is null, you create it. And then, in every case, you set the view's content. </li> <li>The inflate in the getView item should use the parent as parent, and the "false" is there to tell the system not to add the new view to the parent (the gridview will take care of that). If you don't, some layout parameters might get ignored.</li> </ol> <p>The erorr you had was because the views were getting recycled (convertView not null) and you weren't setting the content for those. Hope that helps !</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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