Reputation: 129
I need to download images from server and cache efficiently and need to display in grid view. I don't want to use any libraries.
Can any one help me. Am new to android.
Thanks in advance, Deepak
Upvotes: 1
Views: 3336
Reputation: 765
Use this project and Add four files to your project i.e. https://github.com/thest1/LazyList/tree/master/src/com/fedorvlasov/lazylist
You don't need any Library. It will work standalone.
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;
}
}
Check Bold Strings. in Which custom LazyAdapter shows to set image inside your adapter. That adapter set to Gridview.
Upvotes: 1