MAK
MAK

Reputation: 86

To set an images in a Gallery view by having the ids of the images in Android

I am having a lots of images in res folder and want to select some of them and show them in Gallery view now problem is at run time I have to decide which images i need to select. So how can i achieve that,at run time i have an array with names of an images to be selected.

Integer[] pics = { R.drawable.cocktail1, R.drawable.cocktail2,
        R.drawable.cocktail3, R.drawable.cocktail4, R.drawable.cocktail5,
        R.drawable.cocktail6, R.drawable.cocktail7 };

Want to achieve this but at run time pics array contents will be decided.

Upvotes: 1

Views: 78

Answers (1)

Prasanna
Prasanna

Reputation: 236

gallery.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                // TODO Auto-generated method stub
                @SuppressWarnings("unused")
                imageView.setImageBitmap(pics[arg2]);
            }
        });

Upvotes: 1

Related Questions