所以我的应用程序是这样的:我读取了一个包含各种信息和图像链接的 json(这是在 AsyncTask 的过程 doInBackground 中完成的)。此外,在阅读此过程中的链接后,我还阅读了图片(有关更多信息,请参阅下面的代码)
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 页面添加代码,并使用它而不是我的方法 get view ?...任何帮助或指向比维基上的更完整示例的链接,都会帮助像我这样的初学者:)
- 这个框架也可以在商业应用程序中使用吗?
谢谢 :)