How to enable scrolling on a simpleadapter on Google Glass's firmware X16

谁说胖子不能爱 提交于 2019-12-18 17:24:05

问题


After updating my Google Glass up to XE16 my listview, which I have built by using a simpleadapter, is not able to scroll anymore. Is there a way to manually enable scrolling nonetheless with the GDK or fix this issue?


回答1:


My listview stopped scrolling as well with the X16 update. You can build scrolling back in by doing the following:

In your activity's onCreate method, be sure to:

  1. set the list's choice mode
  2. set the list's clickable property to true.
  3. set the list's onItemClick listener
  4. create a gesture detector (see below)

For example:

myListView = (ListView)findViewById(R.id.MY_LIST_VIEW);
if(myListView != null){
    myListView.setAdapter(mAdapter);
    myListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    myListView.setClickable(true);

    myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
         public void onItemClick(AdapterView<?> parent, View view, int position, long id){
            Log.d("MY_LOG", "click at position " + position);
         }
    });
}

mGestureDetector = createGestureDetector(this);

Now, we need to write a new method for the createGestureDetector() call above (last line). Basically, you can modify the code given in the GDK docs to scroll up and down based on SWIPE_LEFT and SWIPE_RIGHT gestures. Note that in the above code, I assigned my listView to a variable called myListView. Here's a sample method for the gesture detector that will scroll based on the swipe gestures:

private GestureDetector createGestureDetector(Context context) {
    GestureDetector gestureDetector = new GestureDetector(context);
    //Create a base listener for generic gestures
    gestureDetector.setBaseListener( new GestureDetector.BaseListener() {
        @Override
        public boolean onGesture(Gesture gesture) {
            if (gesture == Gesture.TAP) { // On Tap, generate a new number
                return true;
            } else if (gesture == Gesture.TWO_TAP) {
                // do something on two finger tap
                return true;
            } else if (gesture == Gesture.SWIPE_RIGHT) {
                // do something on right (forward) swipe
                myListView.setSelection(myListView.getSelectedItemPosition()+1);
                return true;
            } else if (gesture == Gesture.SWIPE_LEFT) {
                // do something on left (backwards) swipe
                myListView.setSelection(myListView.getSelectedItemPosition()-1);
                return true;
            }
            return false;
        }
    });
    gestureDetector.setFingerListener(new GestureDetector.FingerListener() {
        @Override
        public void onFingerCountChanged(int previousCount, int currentCount) {
          // do something on finger count changes
        }
    });
    gestureDetector.setScrollListener(new GestureDetector.ScrollListener() {
        @Override
        public boolean onScroll(float displacement, float delta, float velocity) {
            // do something on scrolling

            return false;
        }
    });
    return gestureDetector;
}

Hope this helps!



来源:https://stackoverflow.com/questions/23097555/how-to-enable-scrolling-on-a-simpleadapter-on-google-glasss-firmware-x16

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!