【发布时间】:2018-07-11 14:21:09
【问题描述】:
我最近遇到一个问题,我的 android 按钮需要点击两次才能工作。我已经做了很多研究,但这些解决方案都没有帮助。这是我的代码:
这是我定义按钮的方式:
<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 中的一个按钮。以下是我在 Adapter 中设置 OnclickListener 方法的方法! - 不是活动或片段:(我已经在适配器中定义了这个按钮)
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);
}
});
希望你们能帮我找出问题所在。我已经为此工作了两天。非常感谢您的帮助。
【问题讨论】:
-
父(列表项)布局是否也可选择?
-
我看到你使用
android:focusableInTouchMode="false",为什么?是否有任何其他视图将此属性设置为 true? -
@mTak,不,我设置它的原因是因为这是 StackOverflow 的解决方案之一。如果我删除此属性,它仍然不起作用
-
在布局中搜索具有相似属性的其他视图,这些视图可能会在第一次触摸时获得焦点
标签: java android android-button