首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在异步映像加载中使用机器人绑定?

如何在异步映像加载中使用机器人绑定?
EN

Stack Overflow用户
提问于 2014-12-02 18:58:33
回答 1查看 348关注 0票数 2

我如何使用机器人绑定的AdapterView与动态图像加载程序,如离子或毕加索?

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

这就是我所拥有的:

代码语言:javascript
复制
@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;
}

}

代码语言:javascript
复制
@org.robobinding.annotation.PresentationModel
public class LocationPresentationModel implements ItemPresentationModel<Location> {

...
my getter / setter 
...
}

但是把动力装载机放在哪里。当它只是一个项目时会很容易,但是如何使它与位置列表中的每个条目一起工作呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-25 22:42:57

ItemPresentationModel附带了一个updateData方法,我把所有需要的东西都放进去了。这解决了我的问题。

代码语言:javascript
复制
  @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());
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27256895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档