1 回答
![?](http://img1.sycdn.imooc.com/5458477300014deb02200220-100-100.jpg)
TA贡献1846条经验 获得超7个赞
如果你有绘制文件夹下的本地图片为所有一)myntra B)firstCry C)跳房子等等,那么你只是单纯的需要得到基于URL正确绘制。您可以创建工厂类,它将为您提供@DrawableRes
public static @DrawableRes int getDrawable(String url){
if(url.contains("Myntra")) {
return R.drawable.myntra;
} else if(url.contains("Snapdeal")) {
return R.drawable.snapdeal;
}
// Add other if else to support other website url
}
这是修改后的 onBindViewHolder 方法。
@Override
public void onBindViewHolder(WebsiteAdapter.ViewHolder holder, int position) {
Website website = mDataSource.get(position);
holder.url.setText(website.getUrl());
holder.thumbnailImageView.setImageResource(getDrawable(website.getUrl()));
}
添加回答
举报