I'm trying to detect an onFling event for a TextView object. The code below works perfectly for the onDown event, however it fails to get the onScroll or onFling events. Any pointers?
Thanks
package rob.testapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity
{
private GestureDetector myGestDetector;
private TextView mainTextView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myGestDetector = new GestureDetector(this, new SimpleOnGestureListener()
{
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
mainTextView.setText("just scroll'n");
return false;
}
@Override
public boolean onDown(MotionEvent e1)
{
mainTextView.setText("on down");
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
mainTextView.setText("on fling");
return false;
}
});
mainTextView = (TextView)findViewById(R.id.MainText);
mainTextView.setText("Starting app...");
mainTextView.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
myGestDetector.onTouchEvent(event);
return false;
}
});
}
}
The layout is just a TextView inside a LinearLayout.
public boolean onTouch(View v, MotionEvent event)
{
myGestDetector.onTouchEvent(event);
return false;
}
I think you should return true here. You view rejects pointer down event by returning false and don't receive any subsequent events because of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With