2

I am looking for a way to tell which item in a Gallery View has landed in the center after scrolling the Gallery left or right. At the moment I can only get a response when clicking one of the Gallery items, which of course brings it to center. The exact behavior I am trying to accomplish is to be able to scroll the Gallery and have a TextView indicate which item has landed in the center, without having an item actually clicked upon.

Very new at Android, any thoughts would be appreciated.

Thanks!

Ribs
  • 1,449
  • 2
  • 13
  • 27
  • Well I guess this is something that can't be done. It really amazes me that no one conceiving this functionality thought that maybe it would be good to know which one landed in the center after a swipe. Guess not. :/ – Ribs Dec 16 '10 at 21:01

2 Answers2

1

Use the setOnItemSelectedListener like this:

galleryview.setOnItemSelectedListener(new OnItemSelectedListener(){});

//add unimplemented methods to above.

roomtek
  • 3,747
  • 2
  • 21
  • 22
  • thx, I believe I tried that method already but I will check it out and if it works will mark your answer. Busy with other stuff atm so might be a little bit. – Ribs Feb 28 '11 at 19:20
0

I know this question is old and Ribs probably already solved this problem. But since he did not accept the only answer and considering that I myself had the same questioning but could not find better question, I believe it is important for me to reassure that the method described by roomtek DOES work.

Here is some code to make this thing a bit clearer.

gallery.setOnItemSelectedListener(new OnItemSelectedListener(){

    @Override
    public void onItemSelected(AdapterView<?> parent, View view,
            int position, long id) {
        Log.i(TAG,"onItemSelected. position: "+position+", id: "+id);
        mCurrentImage = position;
        title.setText(titlesArray.getString(mCurrentImage));
        description.setText(descArray.getString(mCurrentImage));
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        Log.w(TAG,"onNothingSelected");
    }

});
Bilthon
  • 2,461
  • 8
  • 36
  • 44