The Holo Dev
The Holo Dev

Reputation: 1016

Bitmap not appearing in ListView

I'm attempting to display a listview that includes an image previously downloaded from the internet, as well as some information. The text information is showing up great, but the imageview is not. My code is:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.w("MyApp", "Getting View");

         View row = convertView;

         if(row==null){
              LayoutInflater inflater=getLayoutInflater();
              row=inflater.inflate(R.layout.list_item, parent, false);
         }

         ImageView showcase = null;

         try{
             showcase = new ImageView(ReadingList.this);
         }catch(Exception e){
             Log.w("MyApp", e.toString());
         }

         if(showcase!=null){
             BitmapFactory.Options options = new BitmapFactory.Options();
             options.inSampleSize = 3;

             Bitmap bm = null;

             File dir = new File(PATH + urlIDs[position]);

             if(dir.isDirectory()){
                 Log.w("MyApp","Dir is a directory");
                 for (File child : dir.listFiles()) {
                        String path = child.getAbsolutePath();
                        Log.w("MyApp", path);
                        bm = BitmapFactory.decodeFile(path, options);
                        Log.w("MyApp", "See if bm is null");
                        if(bm!=null){
                            Log.w("MyApp", "bm!=null");
                            showcase.setImageBitmap(bm);
                            break;
                        }
                      }
             }

         }

         TextView title =(TextView)row.findViewById(R.id.list_item_text);
         TextView url = (TextView) row.findViewById(R.id.list_item_url);
         title.setText(Titles[position]);
         url.setText(urlPrefixes[position]);

         return row;
    }
}

Sorry it's a little messy at the moment.. I can see in the logcat as it finds an image in that folder, it passes the bm!=null check, and should be setting that image as the content of the imageView if I'm not mistaken. I can even see in the logcat that it's moved on to the next row item, and I can use the eclipse file manager to see that there is in fact an image at the end of the path received by child.getAbsolutePath

What am I doing wrong?

Upvotes: 0

Views: 126

Answers (1)

Vit Khudenko
Vit Khudenko

Reputation: 28418

What am I doing wrong?

ImageView showcase is not connected to the list item view. You should find that view within the list item view instead, smth like:

ImageView showcase = (ImageView) row.findViewById(R.id.my_icon);

Upvotes: 1

Related Questions