14

ボタンを初めて使用するときにクリックイベントが発生しないという問題がありますが、ボタン以外の画面をクリックしてからクリックすると、問題が発生します。ダイレクトに効く!

私のフラグメント onCreateView には次のものがあります。

    viewAnimator = (ViewAnimator) inflater.inflate(R.layout.fragment_login_supplier, container, false);
    initView(viewAnimator);

そしてinitViewで:

private void initView(ViewAnimator ll) {
......

    errorButton = (Button) errorLayout.findViewById(R.id.buttonError);
    errorButton.setBackgroundResource(btnErrorSelector);
    errorButton.setOnClickListener(FragmentLoginSupplier.this);
.....

}

私のフラグメントは OnClickListener を実装していますが、私の : @Override public void onClick(View vue) {} は初めて何も受け取りません ...

ボタン ID : buttonError

レイアウトの最初の部分:

<ScrollView
    android:id="@+id/scrollViewForm"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top" >

    <LinearLayout
        android:id="@+id/login_form_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/RelativeLayoutErrorMessage"
            android:layout_width="match_parent"
            android:layout_height="@dimen/button_height"
            android:background="@color/DarkGray"
            android:visibility="gone" >

            <ImageView
                android:id="@+id/ImageViewErrorMessage"
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:contentDescription="@string/todo"
                android:src="@drawable/alert_white"
                android:visibility="gone" />

            <TextView
                android:id="@+id/textViewErrorMessage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="5dp"
                android:layout_toLeftOf="@+id/buttonError"
                android:layout_toRightOf="@+id/ImageViewErrorMessage"
                android:text="@string/vous_n_avez_pas_encore_ajout_de_compte"
                android:textColor="@color/white" />

            <Button
                android:id="@+id/buttonError"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_margin="5dp"
                android:background="@drawable/button_suppression_noir_selector" />
        </RelativeLayout>

        <View
            android:id="@+id/RelativeLayoutErrorMessageBottomBorder"
            android:layout_width="wrap_content"
            android:layout_height="1dp"
            android:background="#FFFFFFFF"
            android:visibility="gone" />
4

9 に答える 9

23

これで問題が解決するかどうかはわかりませんが、ボタンのクリックに問題がありました。このコードはうまくいきました。2 回目のクリックは「本物の」クリックです。

<style name="ButtonStyle" parent="@android:style/Widget.Holo.Button">
    <item name="android:focusable">true</item>
    <item name="android:focusableInTouchMode">true</item>
    <item name="android:clickable">true</item>
    <item name="android:background">@drawable/custom_button</item>
    <item name="android:textColor">@color/somecolor</item>
    <item name="android:gravity">center</item>
</style>

試してみて、私に知らせてください。

あなたが試すことができる他の解決策は、abc.javaに追加することです

input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    v.performClick();
                }
            }
        });

<item name="android:focusableInTouchMode">true</item>Xmlで作成します。

うまくいったかどうか教えてください

于 2013-05-06T04:52:06.240 に答える
10

私は単に設定することでこれを解決しました:

<ImageButton
    android:id="@+id/imageButtonFiltroNome"
    ...
    android:clickable="true"
    android:focusable="false"
    android:focusableInTouchMode="false" />
于 2014-04-01T09:35:45.517 に答える
10

errorButton を設定するだけです:

errorButton.setFocusableInTouchMode(false);

または追加

errorButton.setOnTouchListener(new OnTouchListener(){

    @Override
    public boolean onTouch(View view, MotionEvent event) {
        if (MotionEvent.ACTION_UP == event.getAction())
        {
            view.performClick();
            return true;
        }
    return false;
    }
});
于 2013-05-06T07:46:51.687 に答える
2

コントロールがスクロール可能なコンテナー内にある場合は、コンテナーに次のように設定します。

android:descendantFocusability="afterDescendants"
于 2015-11-20T21:08:18.450 に答える
0

私は同じ問題に直面しました。どのように修正したかをお話ししましょう。フォームにxmlがあります。

<RelativeLayout
    android:id="@+id/rlContactUs"
    style="@style/SettingsItemContainer" >
    <com.CustomTextView
        android:id="@+id/tvContactUs"
        style="@style/SettingsItem"
        android:text="@string/contactUs"/>
</RelativeLayout>

SettingsItemContainer のスタイルは次のとおりです。

<style name="SettingsItemContainer">
other things
    <item name="android:clickable">true</item>
    <item name="android:focusable">true</item>
    <item name="android:focusableInTouchMode">true</item>
</style>

現在、相対レイアウトは、タッチしても最初のクリックを受け取りませんでした。だから私はそれを次のように変更しました:

<style name="SettingsItemContainer">
other things
    <item name="android:clickable">true</item>
    <item name="android:focusable">true</item>
    <item name="android:focusableInTouchMode">false</item>
</style>

これで問題は解決しました

于 2015-01-09T12:36:21.373 に答える
0

でこの問題が発生している場合は、 textIsSelectableが「true」に設定されてTextViewいることが原因である可能性があります。この属性を削除するか「false」に設定すると、最初のタップが検出されます。

于 2022-01-11T08:43:52.803 に答える