【问题标题】:How to use Robobinding with async image loading?如何将 Robobinding 与异步图像加载一起使用?
【发布时间】:2014-12-02 18:58:33
【问题描述】:

如何将 Robobinding 的 AdapterView 与动态图像加载器(如 ion 或 picasso)一起使用?

我从 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 
...
}

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

【问题讨论】:

  • 你的问题是怎么解决的?
  • ItemPrensentationModel 带有一个 updateData 方法。这样就解决了。

标签: android picasso android-ion robobinding


【解决方案1】:

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());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 2013-09-11
    • 2021-06-05
    • 1970-01-01
    相关资源
    最近更新 更多