ボタンといくつかの TextViews と EditTexts を含む ScrollView 内に RelativeLayout があります。
私の xml レイアウト ファイルでは、android:onClick を定義していますが、イベントを発生させるには常にボタンを 2 回クリックする必要があります。ボタンは常に最初のクリックでフォーカスを取得し、2 回目のクリックで onClick イベントを発生させます。focusable と focusableInTouchMode の両方を false に設定しようとしましたが、動作は変わりません。
ここに私のレイアウトファイルがあります:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".DensityActivity" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
...
<TextView
...
<TextView
...
<EditText
...
<Button
android:id="@+id/ad_button_calculate"
android:layout_width="112dp"
android:layout_height="wrap_content"
android:layout_below="@id/ad_edit_obs_temp"
android:layout_alignParentRight="true"
android:layout_marginTop="20pt"
android:paddingLeft="6pt"
android:onClick="onClick"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/button_calculate" />
<TextView
...
</RelativeLayout>
</ScrollView>
focusable と focusableInTouchMode が何もしないように見える理由についてのアイデアや提案はありますか?
私の onClick() メソッドが本来あるべきことをしていないのではないかと思ったので、見やすいように単純なものに減らしましたが、同じように動作します。これが私の簡略化された onClick() です:
public void onClick(View view) {
new AlertDialog.Builder(this).setTitle("Argh").setMessage("Watch out!").setNeutralButton("Close", null).show();
}