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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:46:38+00:00 2026-05-27T10:46:38+00:00

I’m having a problem to inflate facebook profile picture into listview. What I’m doing

  • 0

I’m having a problem to inflate facebook profile picture into listview. What I’m doing is once the user click fb image icon, from the JSONArray i retrieve the picture url for each of user and store it in the arraylist. so when I set adapter for my listview, I pass the the url and decode it. Unfortunately, my list view become lagging when i try to scroll down as the adapter still downloading the image. If i comment out code for decoding user profile picture url, my listview working properly but only display name of my friends. below is my code.

        fbimage = (ImageView) findViewById(R.id.fb_contact);        
        fbimage.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            token = fb.getAccessToken();
            final Dialog friends_dialog = new Dialog(PostToWall.this);
            friends_dialog.setTitle("Facebook Friends");
            friends_dialog.setContentView(R.layout.friend_list);

            friendList = (ListView) friends_dialog.findViewById(R.id.fb_friend_list);                                           
            friendList.setOnItemClickListener(PostToWall.this);

            progress = ProgressDialog.show(PostToWall.this, "Facebook Friends",
                                        "Fetching Data", true, true);
            final Handler handler = new Handler(){
                public void handleMessage(Message msg){
                    progress.dismiss();
                    friendList.setAdapter(new FbFriendListAdapter(getApplicationContext(),friendsName, friendsId, friendPic));
                    friends_dialog.show();
                    }
                };

                Thread thread = new Thread(){
                    public void run(){
                        getFriendList();
                        handler.sendEmptyMessage(0);
                    }
                };
                thread.start();                                         
            }
        }); 

getFriendList method:

public void getFriendList(){
        response = fb.request("me/friends");
        JSONObject fbFriendObj = Util.parseJson(response);
        JSONArray fbFriendArray = fbFriendObj.getJSONArray("data");                 
        friendsName = new ArrayList<String>();
        friendsId = new ArrayList<String>();
        friendPic = new ArrayList<String>();
        int i;
        for(i=0;i<=fbFriendArray.length();i++){
            JSONObject friendIDName = fbFriendArray.getJSONObject(i);
            Iterator it = friendIDName.keys();
            while(it.hasNext()){
                String nameId = (String)it.next();
                String name = friendIDName.getString(nameId);
                if(nameId.equals("id")){
                        friendsId.add(name);                            
                friendPic.add(graph_path + name + "/picture");                          
                }else if(nameId.equals("name")){
                    friendsName.add(name);
                }
            }
        }                                
    }

friend list adapter

public class FbFriendListAdapter extends ArrayAdapter<String>{

    private ArrayList<String> friendName;
    //private ArrayList<String> friendID;
    private ArrayList<String> friendPic;
    private Context context;
    Bitmap icon;

    public FbFriendListAdapter(Context c, ArrayList<String> friendName, ArrayList<String> friendID, ArrayList<String> friendPic){
        super(c, R.layout.fb_friend_adapter, 0, friendName);
        this.friendName = friendName;
        //this.friendID = friendID;
        this.friendPic = friendPic;
        this.context = c;
    }

    public int getCount() {
        return friendName.size();       
    }

    public long getItemId(int position) {
        return 0;
    }

    static class ViewHolder{
        public TextView descHolder;
        public ImageView typeHolder;
    }   

    public View getView(int position, View convertview, ViewGroup parent) {
            ViewHolder vh;
            if(convertview==null){              
                LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertview = inf.inflate(R.layout.fb_friend_adapter, null,false);
                vh = new ViewHolder();
                vh.descHolder = (TextView) convertview.findViewById(R.id.fbFriendName);             
                vh.typeHolder = (ImageView) convertview.findViewById(R.id.fbImage);
                convertview.setTag(vh);             
            }
            else{               
                vh = (ViewHolder)convertview.getTag();

            }

            URL img_value = null;
            try {
                img_value = new URL(friendPic.get(position).toString());
                try {
                    icon = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }

            vh.descHolder.setText(friendName.get(position).toString());
            vh.typeHolder.setImageBitmap(icon);
            return convertview;
    }       
}

there is some code i remove for example try catch block to make it easier to read. Hope some one can guide me.

  • 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-27T10:46:38+00:00Added an answer on May 27, 2026 at 10:46 am

    Your listview is lagging because the downloading of images happen in the main(UI) thread,

    You should make use of an Asynctask that will run in the background and download images seamlessly, without causing any lag in the listview

    eg. (think of website, it loads text first and then the images, but does not hang up your screen)

    here is a link to an excellent tutorial from which you can build up your listview logic
    very handy tutorial

    it makes use of an adapter class . going through which you can build adapter for your listview

    Hope this helps

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.