我的 Android 按钮需要点击两次才能工作

My Android Button needs to be tapped twice to work

我最近遇到一个问题,我的 android 按钮需要点击两次才能工作。我已经做了很多研究,但是 none 这些解决方案有所帮助。这是我的代码:

我是这样定义按钮的:

<Button
    android:id="@+id/add_to_list_button"
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:focusableInTouchMode="false"
    android:text=""
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

它是Recycler View Cell中的一个按钮。下面是我在 适配器中设置 OnclickListener 方法的方法! - 不是 Aktivity 或 Fragment:(我已经在适配器中定义了这个按钮)

mAddButton = (Button) itemView.findViewById(R.id.add_to_list_button);

这里是onBindViewHolder方法

holder.mAddButton.setBackgroundResource(R.mipmap.ic_add_hs_24dp);
holder.mAddButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https:xxx"));
                v.getContext().startActivity(browserIntent);
            }
        });

我希望你们能帮我找出问题所在。我已经为此工作了两天。非常感谢您的帮助。

如果您的 RecyclerView 包含接受输入事件的组件,例如 EditText 或 Spinner,则在 OnItemClickListener 或 OnItemLongClickListener() 中捕获点击事件可能会出现问题。

可能的解决方案是将您的 EditText/Spinner 设置为禁用事件,以便将点击事件归入按钮

您可以通过设置

来做到这一点

android:focusable="false"

android:focusableInTouchMode="false"