对于我的项目,我需要从网络上下载图片,因此我已经实现了一个简单的类:
@SuppressWarnings("deprecation")
public class DynamicDrawable extends BitmapDrawable{
private Drawable drawable;
@Override
public void draw(Canvas canvas) {
// override the draw to facilitate refresh function later
if(drawable != null) {
drawable.draw(canvas);
}
Log.d("dnull", String.valueOf(drawable == null));
}
protected void setDrawable(Drawable drawable){
this.drawable = drawable;
}
}
有一个处理程序用于获取和解析图像,将其异步添加到类中并使视图无效,我已经检查过并且正常工作。 drawable变量不为空。 然后将其添加到ImageView中。但是,draw()方法从未被调用。即使它第一次被添加时也是如此。以下是图像进入视图的代码:
@Override
public View getView(int position, View convertView, ViewGroup parent){
View view = convertView;
if(view == null){
view = inflater.inflate(R.layout.view_concerteposter, parent,false);
}
ConcertPoster poster = posters.get(position);
ImageView iconView = (ImageView)view.findViewById(R.id.ticketBuy_icon);
TextView titleView = (TextView)view.findViewById(R.id.ticketBuy_name);
TextView dateView = (TextView)view.findViewById(R.id.ticketBuy_date);
iconView.setImageDrawable(poster.getImage());
System.out.println(poster.getImage());
titleView.setText(poster.getTitle());
dateView.setText(poster.getDate());
return view;
}
是的,我已经检查了这些对象,它们都是正确的,并且它们内部包含了正确的可绘制图形。
如果有需要帮助的地方,请告知。