0

I am making an Avatar object which can be used in XML. When the object starts it is supposed to use picasso to get the users avatar image. It looks like this

public class Avatar extends RoundedImageView {

private static String avatarURL;
private Context context;
public static List<Avatar> avatarList = new ArrayList<>();


public Avatar(Context context) {
    super(context);
    this.context = context;
    init();
}

public Avatar(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    init();
}

public Avatar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.context = context;
    init();
}

private void init(){
    Avatar.avatarList.add(this);
    Picasso.with(context).load(avatarURL).placeholder(R.drawable.default_avatar).into(this);
}

It works great however it makes the xml crash in view mode. Is there a way to either make the xml ignore the Picasso line and just use a default image or for the xml to be able to understand picasso.

Adam Katz
  • 6,999
  • 11
  • 42
  • 74

0 Answers0