我需要从服务器和缓存有效地下载图像,需要在网格视图中显示。我不想使用任何库。
有谁能帮我吗?我是android新手。提前感谢,迪帕克
使用此项目并将四个文件添加到您的项目中,即https://github.com/thest1/LazyList/tree/master/src/com/fedorvlasov/lazylist
你不需要任何库。它将独立工作。
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] data;
private static LayoutInflater inflater=null;
**public ImageLoader imageLoader;**
public LazyAdapter(Activity a, String[] d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
**imageLoader=new ImageLoader(activity.getApplicationContext());**
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.item, null);
TextView text=(TextView)vi.findViewById(R.id.text);;
ImageView image=(ImageView)vi.findViewById(R.id.image);
text.setText("item "+position);
**imageLoader.DisplayImage(data[position], image);**
return vi;
}
}
检查粗体字符串。其中自定义LazyAdapter显示设置适配器内的图像。该适配器设置为Gridview。