如何使用Robobinding与异步图像加载?

时间:2014-12-02 18:58:34

标签: android picasso ion robobinding

我如何将Robobinding的AdapterView与动态图像加载器一起使用,如离子或毕加索?

我从REST服务获取位置列表,其中一个属性是我想在视图中显示的图像的URL。

这就是我所拥有的:

@org.robobinding.annotation.PresentationModel
public class LocationAdapterPresentationModel implements HasPresentationModelChangeSupport {
private final PresentationModelChangeSupport changeSupport;
private final Activity activity;
List<Location> locations;

public LocationAdapterPresentationModel(Activity activity, List<Location> locs){
    locations = locs;
    this.changeSupport = new PresentationModelChangeSupport(this);
    this.activity = activity;
}

@ItemPresentationModel(LocationPresentationModel.class)
public List<Location> getLocations(){
    return new ArrayList<Location>(locations);
}

public void refreshLocations() {
    changeSupport.firePropertyChange("locations");
}

public void setLocations(List<Location> locs){
    this.locations = locs;
}

@Override
public PresentationModelChangeSupport getPresentationModelChangeSupport() {
    return changeSupport;
}

}

@org.robobinding.annotation.PresentationModel
public class LocationPresentationModel implements ItemPresentationModel<Location> {

...
my getter / setter 
...
}

但是放置动态加载器的位置。当它只是一个项目时会很容易,但是如何让它与位置列表中的每个条目一起工作?

1 个答案:

答案 0 :(得分:3)

ItemPresentationModel附带一个updateData方法,我输入了所有需要的东西。这解决了我的问题。

  @Override
public void updateData(Location location, ItemContext itemContext) { 
      ViewGroup itemView = (ViewGroup) itemContext.getItemView();
    ImageView image1 = (ImageView) itemView.findViewById(R.id.image1);
    ImageView image2 = (ImageView) itemView.findViewById(R.id.image2);

    Ion.with(image1)
            .placeholder(R.drawable.loading)
            .error(R.drawable.emptypicture)
            .animateLoad(R.anim.loading_circle)
            .load(location.getPreviewImg1());
}