onScroll方法不起作用

时间:2014-01-22 13:50:35

标签: java android

public class showManga extends Activity implements GestureDetector.OnGestureListener{

GestureDetectorCompat detector;
TextView text; 
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    text=(TextView)findViewById(R.id.text);
    setContentView(R.layout.image);
    this.detector=new GestureDetectorCompat(this,this);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    this.detector.onTouchEvent(event);
    return super.onTouchEvent(event);
}

@Override
public boolean onDown(MotionEvent arg0) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX,
        float velocityY) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public void onLongPress(MotionEvent arg0) {
    // TODO Auto-generated method stub

}
@Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
        float arg3) {
    // TODO Auto-generated method stub
    text.setText("scroll");
    return true;

}
@Override
public void onShowPress(MotionEvent arg0) {
    // TODO Auto-generated method stub

}
@Override
public boolean onSingleTapUp(MotionEvent arg0) {
    // TODO Auto-generated method stub
    return false;
}



}

我不明白为什么这段代码无效。我查了一切。对我来说似乎是对的。请帮我。 onScroll方法无效。

1 个答案:

答案 0 :(得分:1)

在setcontent view

之后放置此行
text=(TextView)findViewById(R.id.text);

喜欢:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.image);
 text=(TextView)findViewById(R.id.text);
    this.detector=new GestureDetectorCompat(this,this);
}