我做了如下编码:
public class MenuFragment extends ListFragment {
private SlideoutHelper mSlideoutHelper;
public final GestureDetector gdt = new GestureDetector(
new GestureListener());
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, new String[] { " First",
" Second", " Third", " Fourth", " Fifth", " Sixth",
" Seventh", " Eighth", " Ninth", " Tenth" }));
getListView().setCacheColorHint(0);
getListView().setOnTouchListener(new OnTouchListener() {
public boolean onTouch(final View view, final MotionEvent event) {
return gdt.onTouchEvent(event);
}
});
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// ((MenuActivity)getActivity()).getSlideoutHelper().close();
Context con = v.getContext();
if (position == 0) {
Toast.makeText(con, "First Clicked", 5).show();
} else {
Toast.makeText(con, "Clicked", 5).show();
}
}
public class GestureListener extends SimpleOnGestureListener {
private final int SWIPE_MIN_DISTANCE = 120;
private final int SWIPE_THRESHOLD_VELOCITY = 2000;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
System.out.println("flingggggggggg");
mSlideoutHelper.close();
return true;
}
return false;
}
}
}
但它不起作用。请帮我。如何在此视图中获得滑动选项?