を完全に理解しようとしてOnTouchListener
いますが、いくつか疑問があります。
私はこのxmlコードを持っています:
<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>
そして、私は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;
}
});
}
}
で false を返すと読みましたがACTION_DOWN
、残りのジェスチャー (MOVE
およびUP
) は機能しません。しかし、このコードでは機能し、「アップ」メッセージが画面に表示されますが、表示されるべきではありません。OnTouch
そのため、イベントの戻り値の意味が完全にはわかりません。
誰かが私を助けることができますか?