My questions are about delay image loading using AQuery如何改造基本代碼轉換爲更高效的AQuery代碼
所以我的應用程序是這樣的:我讀了JSON,包含的各種信息,並鏈接到圖片(這是在程序doInBackground從的AsyncTask完成)。另外,閱讀的鏈接在此過程後,我也看了圖片(見下面的代碼以獲得更多信息)
class GetMessages extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(uri);
// code that reads the json .......
Bitmap picture = null;
try {
URL newurl = new URL(json.getString("pic_url"));
picture = BitmapFactory.decodeStream(newurl.openConnection() .getInputStream());
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// after this, i put all the read info, and the pics in a list of
// objects, that is then usen in the method onPostExecute to populate
// my custom adapter ...see code below
static class ViewHolder {
ImageView picView;
}
public class MyCustomBaseAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private ArrayList<Product> products;
public ArrayList<Product> getProducts() {
return products;
}
public void setProducts(ArrayList<Product> products) {
this.products = products;
}
public MyCustomBaseAdapter(Context context, ArrayList<Product> products) {
this.products = products;
this.mInflater = LayoutInflater.from(context);
}
public int getCount() {
return products.size();
}
public Object getItem(int position) {
return products.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.product_item, null);
holder = new ViewHolder();
holder.picView = (ImageView) convertView.findViewById(R.id.pic_view);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.picView.setImageBitmap(products.get(position).getPicture());
return convertView;
}
正如你已經可以找出...如果我有像15張圖片...的用戶加載所有的信息之前得到昏昏欲睡......
- 我想要做的,就是用你的延遲影像載入中...但是,我似乎無法把拼在一起...怎麼我應該修改我的適配器嗎?
- 我基本上是從你的wiki頁面添加代碼,並使用它代替我的方法獲取視圖? ...任何幫助或鏈接到一個更完整的例子,那麼什麼是維基,將有助於像我這樣的初學者:)
- 這個框架也可以在商業應用程序中使用嗎?
謝謝:)