Chris Allen
Chris Allen

Reputation: 369

Android -- Gallery with page indicator

Has anyone ever put a page indicator at the top of a gallery? Writing your own gallery and overriding onScroll() doesn't cut it because it only updates while the user scrolls (it stops being called while fling inertia and snapping occurs).

It would be nice if there was an easy way of intercepting all gallery motion, but I haven't seen a way to do this.

Thanks in advance!

Upvotes: 1

Views: 6426

Answers (2)

Chris Allen
Chris Allen

Reputation: 369

As it turns out, it's as easy as adding an OnItemSelectedListener().

gallery.setOnItemSelectedListener(new OnItemSelectedListener(){
     @Override
     public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
          guiText.setText((position+1)+" of "+adapter.getCount());
     }
     @Override
     public void onNothingSelected(AdapterView<?> adapter) {
          guiText.setText("");
     }
});

Upvotes: 7

David Hedlund
David Hedlund

Reputation: 129812

I think Jon O's patch on Eric Taix excellent Workspace View, as can be found here, does an excellent job of rolling a custom gallery with a page indicator.

Upvotes: 0

Related Questions