If this is your own app, whether it's in native GDK code or code ported from some Android app, you can follow the steps below to support the navigation of listview, buttons, etc and non-GDK UI components:
- Add
GestureDetector mGestureDetector;
- Add
mGestureDetector = createGestureDetector(this);
in onCreate
;
- Define two methods:
List item
private GestureDetector createGestureDetector(Context context) {
GestureDetector gestureDetector = new GestureDetector(context);
gestureDetector.setBaseListener( new GestureDetector.BaseListener() {
@Override
public boolean onGesture(Gesture gesture) {
if (gesture == Gesture.TAP) {
process(mListView.getSelectedItem());
return true;
} else if (gesture == Gesture.SWIPE_RIGHT) {
mListView.setSelection(mListView.getSelectedItemPosition()+1);
return true;
} else if (gesture == Gesture.SWIPE_LEFT) {
mListView.setSelection(mListView.getSelectedItemPosition()-1);
return true;
}
return false;
}
});
return gestureDetector;
}
// this method is required for tap on touchpad to work!
public boolean onGenericMotionEvent(MotionEvent event) {
if (mGestureDetector != null) {
return mGestureDetector.onMotionEvent(event);
}
return false;
}
A complete working sample is available at https://github.com/xjefftang/launchy/commit/66f17bd5bf920800ce277df5eeb6ea912b877692