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

  • Home
  • SEARCH
  • 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 8955909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:39:46+00:00 2026-06-15T14:39:46+00:00

I am trying to load bitmap image to listview from sdcard but imageview is

  • 0

I am trying to load bitmap image to listview from sdcard but imageview is not showing image.

Here is my code to get image from SDCard:

public static Bitmap getArtwork(Context context, int album_id) {

        ContentResolver res = context.getContentResolver();
        Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
        if (uri != null)
        {
            InputStream in = null;
            try 
            {
                in = res.openInputStream(uri);
                return BitmapFactory.decodeStream(in, null, sBitmapOptions);
            } catch (FileNotFoundException ex) 
            {
                // The album art thumbnail does not actually exist. Maybe the user deleted it, or
                // maybe it never existed to begin with.
            } finally
            {
                    if (in != null)
                    {
                        try {
                            in.close();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
             }
        return null;
    }

Code to display Image and text in listview :

public class AlbumList extends ListActivity{

    public final ArrayList<HashMap<String, Object>> songsList = new ArrayList<HashMap<String, Object>>();
    public final ArrayList<HashMap<String, Object>> songsListData = new ArrayList<HashMap<String, Object>>();
    private Context context; 
    ListAdapter adapter;
    private static final BitmapFactory.Options sBitmapOptions = new BitmapFactory.Options();
    private static final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");

    //Context contentResolver;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list);
        context = this;

    final String[] cursor_cols = { MediaStore.Audio.Media._ID,
                    MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM,
                    MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA,
                    MediaStore.Audio.Media.ALBUM_ID,
                    MediaStore.Audio.Media.DURATION };
              Cursor cursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, cursor_cols, null, null, null);
              if (cursor == null) 
              {
                  //Query Failed , Handle error.
              }
              else if (!cursor.moveToFirst()) 
              {
                 //No media on the device.
              }
              else
              {   
                  int albumName = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM);
                  int id = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID);

                  for(int i=0;i<cursor.getCount();i++)
                  {
                            String Name = cursor.getString(albumName);
                            Integer albumid = cursor.getInt(id);                        

                            Bitmap bitmap = null;
                            bitmap = getArtwork(context, albumid);
                            if(bitmap == null)
                            {
                                bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.icon);
                            }
    //                      ImageView iv = (ImageView) findViewById(R.id.list_image);
    //                      iv.setImageBitmap(bitmap);
                            HashMap<String, Object> song = new HashMap<String, Object>();
                            song.put("albumArt", bitmap);
                            song.put("albumName", Name);  
                            // Adding each song to SongList
                            songsList.add(song); 
                            cursor.moveToNext();
                   }
               }
               cursor.close(); 

                // looping through playlist
                for (int i = 0; i < songsList.size(); i++) {
                    // creating new HashMap
                    HashMap<String, Object> song = songsList.get(i);
                    // adding HashList to ArrayList
                    songsListData.add(song);
                }

                // Adding menuItems to ListView
                 String[] from = {"albumArt" , "albumName" };
                 int[] to={R.id.list_image , R.id.albumName};
                 adapter = new SimpleAdapter(this, songsListData,R.layout.list_item, from, to);
                 setListAdapter(adapter);
}

I have tried to display single image in imageview which works for same code. But for listview i am not getting image. So what should i do??
Pleaze suggest me some solution.
Thanx.

  • 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-06-15T14:39:47+00:00Added an answer on June 15, 2026 at 2:39 pm

    ListViews inflate what you tell them to. You should make an xml layout and call it list_item, in here arrange the ImageView and Textview the way you want. Make sure to set the Containing layout’s height to wrap content.

    Now when you are inflating views in your list view, inflate this item you made instead. Then set the textview and imageview in this inflated layout to what you want.

    for example in you listview adapter do something similar to this.

    @Override
      public View getView(int position, View convertView, ViewGroup parent) {
    
     if(convertView==null){
       convertView = li.inflatelayout(R.layout.list_item);
    
        }
        MyListItemModel item = items.get(position);
         // replace those R.ids by the ones inside your custom list_item layout.
         TextView label = (TextView)convertView.findViewById(R.id.item_textview);
         label.setText(text);
         ImageView iv= (Imageview)convertView.findViewById(R.id.item_imageview);
        iv.setsourceimage(bitmap);
    
        return convertView;
    }
    

    you can also set their onclick listener’s here if you want.

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

Sidebar

Related Questions

I'm trying to load an image from the web. The code I have so
i'm trying to load image from local disk, and it's working. But my problem
I'm trying to load image (not URL) from either camera or gallery and save
I'm trying to load some images using Bitmap.getBitmapResource() , but it takes about 2
While trying to load a Bitmap onto a SWFLoader the Event.COMPLETE event is not
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
Trying to load a small .txt file into mysql but get all my data
I trying to load and save setting with this code but when I closing
I am trying to load a bitmap into the canvas following the example here.
I am trying to load a movement map from a PNG image. In order

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.