androidgoogle-glassgoogle-gdkcardscrollview

How to know a user as moved to a new Card in a Google Glass app?


Is there a way for the CardScrollView or CardScrollAdapter to let me know when the user moves from one card to another?

Initially I was using the GestureDetector to detect swipes to the left or right, but in Glass applications users can use, e.g., two-finger swipes to quickly pan and move to a distant card (or even voice controls).

There must be a better way to know exactly when a new card is displayed than to track all these directional events.

I know CardScrollView.getSelectedItemPosition() gives me the current card in view, but not exactly when a new card is displayed.

I also thought that CardScrollAdapter.getView() would run every time a new card is displayed, but in Glass applications it runs once in the beginning of the activity execution.

Any help would be great.


Solution

  • The solution is actually in the documentation as suggested by @EntryLevelDev

    CardScrollView notifies you with the following listener interfaces that are inherited from AdapterView:

    AdapterView.OnItemSelectedListener - An item is selected after the user finishes scrolling through the list and settles on an item.

    from: https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/widget/CardScrollView#onAttachedToWindow()