AQuery不在Android Studio中加载图像
我试图通过适配器通过URL将图像加载到我的ListView,但AQuery似乎没有将URL加载到ImageView。我曾经尝试过用毕加索图像加载器来做这件事,它很管用,但我更喜欢AQuery,我需要解决这个问题。我正在使用Android StudioAQuery不在Android Studio中加载图像,android,android-activity,listview-adapter,aquery,Android,Android Activity,Listview Adapter,Aquery,我试图通过适配器通过URL将图像加载到我的ListView,但AQuery似乎没有将URL加载到ImageView。我曾经尝试过用毕加索图像加载器来做这件事,它很管用,但我更喜欢AQuery,我需要解决这个问题。我正在使用Android Studio public class FeedAdapter extends ArrayAdapter<ActivityTable> { ArrayList<ActivityTable> activities = new Ar
public class FeedAdapter extends ArrayAdapter<ActivityTable> {
ArrayList<ActivityTable> activities = new ArrayList<ActivityTable>();
Context ctx;
int resource;
AQuery aq;
public FeedAdapter(Context context, int resource, ArrayList<ActivityTable> activityList) {
super(context, resource, activityList);
this.activities = activityList;
this.ctx = context;
this.resource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.newsfeed_single, null);
}
ActivityTable p = new ActivityTable(); //Object of type ActivityTable
for(ActivityTable item: activities) {
p = activities.get(position);
}
if (p != null) {
TextView owner_text = (TextView) v.findViewById(R.id.post_owner);
ImageView post_picture = (ImageView) v.findViewById(R.id.post_media);
owner_text.setText(p.getUser().getFname());
AQuery aq = new AQuery(ctx);
aq.id(R.id.post_media).image(p.getURL()); //getURL() Returns the Image URL
//The URL is valid and I checked whether it works through Picasso Image Loader
}
return v;
}
}
公共类FeedAdapter扩展ArrayAdapter{
ArrayList活动=新建ArrayList();
上下文ctx;
智力资源;
aq;
公共FeedAdapter(上下文上下文、int资源、ArrayList活动列表){
超级(上下文、资源、活动列表);
this.activities=activityList;
this.ctx=上下文;
这个资源=资源;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
拉平机vi;
vi=LayoutInflater.from(getContext());
v=vi.充气(R.layout.newsfeed_single,null);
}
ActivityTable p=new ActivityTable();//ActivityTable类型的对象
对于(活动表项:活动){
p=活动。获取(位置);
}
如果(p!=null){
TextView所有者\u text=(TextView)v.findViewById(R.id.post\u所有者);
ImageView post_图片=(ImageView)v.findViewById(R.id.post_媒体);
owner_text.setText(p.getUser().getFname());
水渠aq=新水渠(ctx);
aq.id(R.id.post_media).image(p.getURL());//getURL()返回图像URL
//URL是有效的,我通过毕加索图像加载器检查了它是否有效
}
返回v;
}
}
应用程序在ListView中正确加载“名称”字段,但在ImageView中保留空白。我做错了什么?使用Android图像下载和缓存库首先,您需要使用静态类 像这样 在ViewHolder类中添加字符串url 而不是在getView上将其添加到加载
是的。但这里面有很多奇怪的问题。然而,当我滚动到listview的底部并向上滚动时,一些图像会消失。加载到静态类“ViewHolder”的图像Url,如果(Url==null | | Url.equals(ViewHolder.Url)){ViewHolder.Url=Url;//load image}我没有得到。你能把它贴出来作为答案吗?你解决了这个问题吗?我在从eclipse迁移应用程序时遇到了类似的问题,在eclipse中,aquery似乎工作得很好。
if (viewHolder.url == null || url.equals(viewHolder.url)){
viewHolder.url = url;
// load image
}