我使用ParseQueryAdapter在我的应用程序的列表视图中加载图像,但加载速度非常慢,我已经在不同的wifis / 4G上尝试了它,它仍然说同样的。这是我的代码或Parse本身的问题吗?这是代码:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.view_snyps);
ph = null;
ctx = this;
//p = (ParseImageView)findViewById(R.id.snyp_preview_image);
//p.setVisibility(View.GONE);
adapter = new MyAdapter(this);
query.whereEqualTo("username", ParseUser.getCurrentUser().getUsername());
listview = (ListView)findViewById(R.id.imageList);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position,
long id) {
// TODO Auto-generated method stub
query.findInBackground(new FindCallback<ParseObject>(){
@Override
public void done(List<ParseObject> objs, ParseException e) {
// TODO Auto-generated method stub
if(e == null){
ph = objs.get(position);
file = ph.getParseFile("photo");
if(file != null){
Log.d("File name",file.getName());
go = true;
}
ctx.startActivity(new Intent(ctx,ImageCloseup.class));
}
}
});
}
});
这是我的适配器:
public class MyAdapter extends ParseQueryAdapter<Photo> {
public MyAdapter(Context context
) {
super(context, new ParseQueryAdapter.QueryFactory<Photo>() {
@Override
public ParseQuery<Photo> create() {
// TODO Auto-generated method stub
ParseQuery<Photo> query = new ParseQuery<Photo>("Photo");
query.whereEqualTo("username", ParseUser.getCurrentUser().getUsername());
return query;
}
});
}
@Override
public View getItemView(Photo photo, View v, ViewGroup parent){
if(v ==null){
v = View.inflate(getContext(), R.layout.adapter_item, null);
}
super.getItemView(photo, v, parent);
ParseImageView imageView = (ParseImageView)v.findViewById(R.id.snyp_image);
ParseFile file = photo.getParseFile("photo");
if(file!=null){
imageView.setParseFile(file);
imageView.loadInBackground(new GetDataCallback(){
@Override
public void done(byte[] arg0, ParseException arg1) {
// TODO Auto-generated method stub
if(arg1 == null){
Log.d("success","file got");
}
}
});
}
return v;
}
}
慢慢地,我的意思是,有些图像会加载,但其他图像会加载 加载时间长达几分钟。