V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
aliehuhu
V2EX  ›  Android

怎么把 class MyGestureListener extends GestureDetector.SimpleOnGestureListener 这段放到一个单独的文件里呢?

  •  
  •   aliehuhu · 2018-06-24 06:39:07 +08:00 · 8944 次点击
    这是一个创建于 2379 天前的主题,其中的信息可能已经有所发展或是发生改变。
    public class MainActivity extends AppCompatActivity {
    private GestureDetector mDetector;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    View myView = findViewById(R.id.my_view);
    mDetector = new GestureDetector(this, new MyGestureListener());
    myView.setOnTouchListener(touchListener);
    }
    View.OnTouchListener touchListener = new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    return mDetector.onTouchEvent(event);

    }
    };
    class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
    @Override
    public boolean onDown(MotionEvent event) {
    Log.d("TAG","onDown: ");
    return true;
    }
    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
    Log.i("TAG", "onSingleTapConfirmed: ");
    return true;
    }
    @Override
    public void onLongPress(MotionEvent e) {
    Log.i("TAG", "onLongPress: ");
    }
    @Override
    public boolean onDoubleTap(MotionEvent e) {
    Log.i("TAG", "onDoubleTap: ");
    return true;
    }
    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    Log.i("TAG", "onScroll: ");
    return true;
    }
    @Override
    public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
    Log.d("TAG", "onFling: ");
    return true;
    }
    }
    }
    1 条回复    2018-06-27 10:38:11 +08:00
    kwanzaa
        1
    kwanzaa  
       2018-06-27 10:38:11 +08:00
    class MainActivity : AppCompatActivity {
    }

    class MyGestureListener : GestureDetector.SimpleOnGestureListener {
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2187 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 16:12 · PVG 00:12 · LAX 08:12 · JFK 11:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.