I Need To Add A Imageview Or Webview In My Listview
I got a problem. I got some code which I'm not going to put all here because it's to big. But I got a listview. And i do it like this: lv = (ListView) findViewById(R.id.list); (He
Solution 1:
At first,
WebView takes more memory than ImageView. So I recommend you to use ImageView.
At Second,
Check out following URLs.
Lazy load of images in ListView
In this article, The first library, which I have used, is small and customizable library. It uses thread pool and seems to control transfers. The second library, which I haven't used, is larger. But more methods in this library seem to make it easy to control various configurations.
Finally,
I think you should create your own Adapter, extending SimpleAdapter(or CursorAdapter, or…). like following pseudo code.
public class MySimpleAdapter extends SimpleAdapter {
private ImageLoader mImageLoader;
private int mResource;
private LayoutInflater inflater;
public static class ViewHolder {
public ImageView img;
public TextView txt;
}
public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
mResource = resource;
mImageLoader = new ImageLoader(context);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.cell_text, null);
holder = new ViewHolder();
holder.txt = (TextView) convertView.findViewById(R.id.txt);
holder.img = (ImageView) convertView.findViewById(R.id.img);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.txt.setText("something text");
mImageLoader.displayImage("url", holder.img);
return convertView;
}
}
Solution 2:
You Can use [androidQuery]https://code.google.com/p/android-query/ It has a thread pool. It load images in different ways. Has the option to down sample images to save memory. Made by google :)
Post a Comment for "I Need To Add A Imageview Or Webview In My Listview"