Search code examples
javaandroidtwittertwitter4j

How to get user's profile image from status object, twitter4j? (Android)


I want to know how I can get at least the URL from the user's profile image from a status object.

This For statement is the one that generate a timeline in my android application.

The only thing that lasts is to get the URL from the status object.

LinearLayout ll = new LinearLayout(TimeLine.this);
ll = (LinearLayout)findViewById(R.id.linearlayout2);

for (twitter4j.Status status : statuses) {

                    LinearLayout ll2 = new LinearLayout(TimeLine.this);
                    ll2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                    ll2.setOrientation(LinearLayout.HORIZONTAL);

                    ll.addView(ll2);

                    ImageView i = new ImageView(TimeLine.this);
                    Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
                      i.setImageBitmap(bitmap); 

                    ll2.addView(i);

                    LinearLayout ll3 = new LinearLayout(TimeLine.this);
                    ll3 = (LinearLayout)findViewById(R.id.linearlayout2);

                    ll2.addView(ll3);

                    TextView tv1 = new TextView(TimeLine.this);
                    tv1.setText(status.getUser().getName());
                    tv1.setGravity(Gravity.LEFT);
                    tv1.setTypeface(null, Typeface.BOLD);

                    ll3.addView(tv1);

                    TextView tv2 = new TextView(TimeLine.this);
                    tv2.setText(status.getText());

                    ll3.addView(tv2);

                    TextView tv12 = new TextView(TimeLine.this);
                    tv12.setText(" ");

                    ll.addView(tv12);
                }   

Solution

  • I solved, Status object have his own user object. User object have a method called getProfileImageURL();

    so i... :

    ImageView i = new ImageView(TimeLine.this);
    
    User user = status.getUser();
    URL = user.getProfileImageURL();
    
    new ImageLoadTask(URL,i).execute();
    LinearLayout.LayoutParams layoutParams  = new LinearLayout.LayoutParams(140,140);
    i.setLayoutParams(layoutParams);
    
    ll2.addView(i);
    

    Now it works 100%