Sana
Sana

Reputation: 9915

Android: Gallery view, can we name the images?

When we display the images in a Gallery view in Android, is their any way to set a title or set image name for the gallery items?

Technically I would like to name each and every gallery item. Is this possible?

Thanks, Sana.

Upvotes: 1

Views: 1876

Answers (1)

Marcos Vasconcelos
Marcos Vasconcelos

Reputation: 18276

It's possible, with two solutions.

You can has these components for titles (Such a TextView) and update its value in the setOnItemSelectedListener.onItemSelected method, that was called when you are flinging your itens around with the new object that will be in the center.

In this case: lets say you have an LinearLayout with an TextView with id: "title" and below it an Gallery with id: "itens".

You should have a method like this:

    title = (TextView) findViewById(R.id.title);
    gallery = (Gallery) findViewById(R.id.itens);

    coverflow.setAdapter(yourSimpleAdapterWithYourData);

    coverflow.setCallbackDuringFling(true);
    coverflow.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            MyObject book = myData.get(arg2);
            title.setText(book.getTitle());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

OR

You can write your own adapter and inflate a layout witch you can set the title there.

Upvotes: 1

Related Questions