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

Dev
  • 119
  • 1
  • 4
  • 13
  • Why don't you want to use any libraries? I'd recommend Picasso for the image loading an caching and a custom Adapter that extends from BaseAdapter. – msal Jun 24 '14 at 06:58
  • Downloading: http://stackoverflow.com/questions/15549421/how-to-download-and-save-an-image-in-android Displaying and Caching: http://developer.android.com/training/displaying-bitmaps/index.html Why no libraries? Working with bitmaps withoug running in OutOfMemoryExceptios is not the easiest task for beginners. – Apfelsaft Jun 24 '14 at 07:01
  • also universal-image-loader https://github.com/nostra13/Android-Universal-Image-Loader is best one – Bhavin Chauhan Jun 24 '14 at 07:01

1 Answers1

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.

user1621629
  • 765
  • 7
  • 19
  • 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)' ? – Dev Jun 24 '14 at 10:42
  • Check getview portion where you have instance of ImageLoader class and method `imageLoader.DisplayImage(data[position], image)` – user1621629 Jun 24 '14 at 10:46