将我的Google Glass更新到XE16后,我使用simpleadapter构建的listview无法再滚动。有没有办法手动启用滚动GDK或修复此问题?
答案 0 :(得分:6)
我的listview也在X16更新时停止了滚动。您可以通过执行以下操作来重新构建滚动:
在您的活动的onCreate
方法中,请务必:
onItemClick
侦听器例如:
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);
现在,我们需要为上面的createGestureDetector()
调用(最后一行)编写一个新方法。基本上,您可以修改GDK文档中给出的代码,以根据SWIPE_LEFT
和SWIPE_RIGHT
手势向上和向下滚动。请注意,在上面的代码中,我将listView分配给名为myListView
的变量。以下是基于滑动手势滚动的手势检测器的示例方法:
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;
}
希望这有帮助!