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 7656631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:48:58+00:00 2026-05-31T12:48:58+00:00

I’m trying to set a drawable in a list. My list doesn’t contain just

  • 0

I’m trying to set a drawable in a list. My list doesn’t contain just an image.
I’m populating it from a list_item.xml with severals TextViews and one ImageView.

I don’t have any problem if my image is store in the Res android folder, but here I’m loading this image from a database.

Right now i’m using this king of method :

SimpleAdapter adapter = new SimpleAdapter(this.getBaseContext(), list,
R.layout.xml_leaderboard_item, keys, views);

Is there a way to add this drawable/bitmap in my list ? or maybe put that image in the Res folder programmatically so I can use it ?

  • 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-31T12:48:59+00:00Added an answer on May 31, 2026 at 12:48 pm

    I was finally able to do what I wanted. Here is the result :

    enter image description here

    I’m downloading these pictures asynchronously from my database. I was having trouble adding it to a ListView…
    Here’s my code for those who might be interested.

    public class LeaderboardScreen extends ListActivity implements View.OnClickListener
    {
        private UserAdapter             adapter;
        private ArrayList<User>         users;
        private UserPictureDownloader   user_picture_cache;
        ...
    
        protected void onCreate(Bundle saved_instance_state)
        {
            ...
            users = new ArrayList<User>();
            adapter = new UserAdapter(this, R.layout.xml_leaderboard_item, users);
            user_picture_cache = new UserPictureDownloader();
            setListAdapter(adapter);     
            ...
        }     
    
    
        private class UserAdapter extends ArrayAdapter<User>
        {
            private ArrayList<User>     users;
    
            public UserAdapter(Context context, int text_view_res_id, ArrayList<User> users)
            {
                super(context, text_view_res_id, users);
                this.users = users;
            }
    
            public View         getView(int position, View view, ViewGroup parent)
            {
                LayoutInflater layout = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = layout.inflate(R.layout.xml_leaderboard_item, null);
    
    
                ImageView iv_pic = (ImageView)view.findViewById(R.id.lead_pic);
                TextView et_position = (TextView)view.findViewById(R.id.lead_position);
                TextView et_user = (TextView)view.findViewById(R.id.lead_user);
                TextView et_score = (TextView)view.findViewById(R.id.lead_s_value);
                TextView et_reput = (TextView)view.findViewById(R.id.lead_r_value);
                TextView et_contrib = (TextView)view.findViewById(R.id.lead_c_value);
                TextView et_bronze = (TextView)view.findViewById(R.id.lead_bronze_value);
                TextView et_silver = (TextView)view.findViewById(R.id.lead_silver_value);
                TextView et_gold = (TextView)view.findViewById(R.id.lead_gold_value);
    
                User current_user = users.get(position);
                if (current_user != null)
                {               
                    // Set available informations right away.
                    et_position.setText(String.valueOf(position + 1));
                    et_user.setText(current_user.GetLogin());
                et_score.setText(String.valueOf(current_user.GetScore()));
                et_reput.setText(String.valueOf(current_user.GetReputation()));
                et_contrib.setText(String.valueOf(current_user.GetNumberOfQuestionPost()));
                et_bronze.setText(String.valueOf(current_user.GetBadgeBronze()));
                et_silver.setText(String.valueOf(current_user.GetBadgeSilver()));
                et_gold.setText(String.valueOf(current_user.GetBadgeGold()));
    
                // Fetch user image asynchronously.
                final int pos = position;
                final String user_login = current_user.GetLogin();
                final ImageView _iv_pic = iv_pic;
    
                final Handler handler = new Handler()
                    {
                    @Override
                    public void         handleMessage(Message message)
                    {
                        _iv_pic.setImageDrawable((Drawable)message.obj);
                    }
                };
    
                Thread thread = new Thread()
                {
                    @Override
                    public void         run()
                    {
                        try
                        {
                            Drawable dwb = (Drawable)user_picture_cache.GetCachedObject(user_login, handler);
                            handler.sendMessage(handler.obtainMessage(0, dwb));
                        }
                        catch (Exception e) {   Log.e(TAG, e.getMessage()); }
                    }
                };
                thread.start();
            }
            return view;
        }
    }   
    

    The DownloadCache class :

    public class DownloadCache
    {
        private final String    TAG = "DownloadCache";
    
        private ConcurrentHashMap<String, CountDownLatch>   queued_downloads;
        private ConcurrentHashMap<String, Object>           cache;
    
        public DownloadCache()
        {
            queued_downloads = new ConcurrentHashMap<String, CountDownLatch>();
            cache = new ConcurrentHashMap<String, Object>();
        }
    
    
        public Object GetCachedObject(String url, Handler handler) throws InterruptedException
        {
            // Check for a running download, if found wait for its result.
            CountDownLatch complete_event = queued_downloads.get(url);
            if (complete_event != null)
            complete_event.await();
    
            // Check for cached object.
            Object obj = cache.get(url);
            if (obj != null)
                return obj;
    
            obj = StartDownload(url, handler);
            return obj;
        }
    
    private Object StartDownload(String url, Handler handler)
        {
            CountDownLatch complete_event = new CountDownLatch(1);
            queued_downloads.put(url, complete_event);
    
            Object obj = DoDownloadWork(url, handler);
            cache.put(url, obj);
    
            queued_downloads.remove(url);
    
            complete_event.countDown();
            return obj;
        }
    
        public Object DoDownloadWork(String url, Handler handler)
        {
            return null;
        }
    }
    

    Hope this help.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am currently running into a problem where an element is coming back from
In my XML file chapters tag has more chapter tag.i need to display chapters

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.