skip to Main Content

i’m trying to show facebook user’s profile pic using facebook graph api url and user’s name.

String Name = jsonObjectlike.getString("name");
String UserIds = jsonObjectlike.getString("id");
URL url = new URL("https://graph.facebook.com/" + listid + "/picture?type=small");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());

HashMap<String, String> contact = new HashMap<>();
  contact.put("picid", bmp);
  contact.put("name", Name);
  contactList.add(contact);

and here is simpleAdapter to show in listview:

SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, contactList,R.layout.activity_listview, new String[]{"picid", "name"}, new int[]{R.id.imageView1,R.id.name});
simpleList.setAdapter(adapter);

I successfully show name in the listView but image is not showing,

3

Answers


  1. Chosen as BEST ANSWER

    I fixed myself by creating custom listView adapter that contains decoded image url and text. It works perfect for me.


  2. String Name = jsonObjectlike.getString("name");
    String UserIds = jsonObjectlike.getString("id");
    URL url = new URL("https://graph.facebook.com/" + listid + "/picture?type=small");
    
    HashMap<String, String> contact = new HashMap<>();
    //contact.put("picid", bmp);<- use Image URL not bitmap
    contact.put("picid", url);
    contact.put("name", Name);
    contactList.add(contact);
    

    And in your SimpleAdapter handle is picid and show in Imageview with Glide library.

    Login or Signup to reply.
  3. ImageView user_picture;
     userpicture=(ImageView)findViewById(R.id.userpicture);
     URL img_value = null;
     img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
     Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
     userpicture.setImageBitmap(mIcon1);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search