I'm trying to understand full the OnTouchListener, but I have some doubts.
I have this xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.pablo.MainActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
And I have implemented this code i java:
public class MainActivity extends Activity {
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button)findViewById(R.id.button1);
b.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN:
Toast.makeText(getBaseContext(), "boton down",Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_UP:
Toast.makeText(getBaseContext(), "boton up",Toast.LENGTH_SHORT).show();
break;
}
return false;
}
});
}
}
I have read when I return false in ACTION_DOWN, the rest of the gesture (MOVE and UP) doesn't work. But it works in this code, the "up" message is shown on screen, and it shouldn't. So I don't understand completely what is the meaning of the return value in the OnTouch event.
Can somebody helps me?
Assuming your question is "what does the return value mean on onTouch"?
If you looked at documentation, you would see;
Returns True if the listener has consumed the event, false otherwise.
Have a look at the documentation here.
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