图片未加载。当我使用ParseQueryAdapter时它正在工作,但我认为这会使listview更加流畅。以前我也尝试过注释掉的代码,但这也不是一件好事。这是我使用Picasso的BaseAdapter的代码:
public class PicassoAdapter extends BaseAdapter {
private Context myContext;
LayoutInflater inflater;
ParseFile p;
String url;
List<String> s = new ArrayList<String>();
List<ParseFile> mpl;
static class ViewHolder{
ImageView i;
}
public PicassoAdapter(Context c,List<ParseFile> pl){
this.myContext = c;
inflater = LayoutInflater.from(this.myContext);
this.mpl = pl;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return this.mpl.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return this.mpl.get(position);
}
@Override
public long getItemId(int id) {
// TODO Auto-generated method stub
return id;
}
@Override
public View getView(int position, View v, ViewGroup parent) {
final ViewHolder viewHolder;
p = (ParseFile)getItem(position);
// TODO Auto-generated method stub
if(v == null){
v = inflater.inflate(R.layout.adapter_item3, null);
viewHolder = new ViewHolder();
viewHolder.i = (ImageView)v.findViewById(R.id.snyp_image_new);
v.setTag(viewHolder);
}
else{
viewHolder = (ViewHolder)v.getTag();
}
/*ParseQuery<ParseObject> query = ParseQuery.getQuery("Photo");
query.whereEqualTo("username", ParseUser.getCurrentUser().getUsername());
query.findInBackground(new FindCallback<ParseObject>(){
@Override
public void done(List<ParseObject> objs, ParseException e) {
// TODO Auto-generated method stub
if(objs!=null){
for(int i = 0; i < objs.size();i++){
p = objs.get(i).getParseFile("photo");
url = p.getUrl();
s.add(url);
}
}
}
});
for(int x = 0;x<s.size();x++){
Picasso.with(myContext).load(s.get(x)).into(viewHolder.i);
}
*/
Picasso.with(myContext).load(p.getUrl()).into(viewHolder.i);
return v;
}
}
答案 0 :(得分:0)
这有点晚了,但getUrl()
上的ParseFile
方法会返回文件系统上的本地网址。在您的方法中,您只能引用ParseFile对象,但尚未将其下载到您的设备,因此getUrl()不会指向有意义的文件。
如果您使用p.loadInBackground()
,您将能够在该方法的回调中访问该文件的URL,但这可能不是最佳解决方案。