1

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

3

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

this one i have already. but i don't know how to manage grid view in it. Can you post me the bit of code which i want to use inside 'public View getView(int position, View convertView, ViewGroup parent)' ?
Check getview portion where you have instance of ImageLoader class and method imageLoader.DisplayImage(data[position], image)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.