Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

EcoGallery Sample Code

stefalda edited this page Dec 15, 2013 · 3 revisions

This is a simplified sample that shows how easy to use EcoGallery.

1- Include 'EcoGallery' android library to your project. (Eclipse project: properties -> Android -> Library - Add)

2- Create 3 images, copy them to the drawable folder and name them: one.png, two.png and three.png

3- Add this to your layout:

<us.feras.ecogallery.EcoGallery
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

4- In your activity add the following adapter:

private class ImageAdapter extends BaseAdapter {
    private Context context;

    ImageAdapter(Context context) {
        this.context = context;
    }

    public int getCount() {
        return 3;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        // Not using convertView for simplicity. You should probably use it in real application to get better performance.
        ImageView imageView = new ImageView(context);
        int resId;
        switch (position) {
            case 0: resId = R.drawable.one;
                break;
            case 1: resId = R.drawable.two;
                break;
            case 2: resId = R.drawable.three;
                break;
            default: resId = R.drawable.one;
        }
        imageView.setImageResource(resId);
        return imageView;
    }
}

5- In onCreate Method add the following:

    EcoGallery ecoGallery = (EcoGallery) findViewById(R.id.gallery);
    ecoGallery.setAdapter(new ImageAdapter(this));
Clone this wiki locally