参考these tutorials and examples,我尝试实施滑动操作。为此,我在MainActivity的onCreate方法中编写了以下代码。
ActivitySwipeDetector swipe = new ActivitySwipeDetector(this, null);
RelativeLayout swipe_layout = (RelativeLayout) findViewById(R.id.mainll);
swipe_layout.setOnTouchListener(swipe);
现在我几乎没有问题 -
像往常一样感谢您的帮助。
答案 0 :(得分:1)
好吧没关系,我想我明白了......
public class MainActivity extends Activity implements SwipeInterface {
public static int CURR_BOOK_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivitySwipeDetector swipe = new ActivitySwipeDetector(this, (SwipeInterface) this);
RelativeLayout swipe_layout = (RelativeLayout) findViewById(R.id.mainll);
swipe_layout.setOnTouchListener(swipe);
}
......................
....................
}
答案 1 :(得分:1)
由于行activity.onRightToLeft(v);
和activity.onLeftToRight(v);
,您将在onRightToLeftSwipe和onLeftToRightSwipe中获得NullPointerException。您可以在ActivitySwipeDetector
类中实现所有内容并删除这些内容(但这不是一个好的解决方案)或在您自己的活动上实现,将此活动标记为implements SwipeInterface
并将this
作为ActivitySwipeDetector
的第二个参数。