I recently got a problem that my android button needs to be tapped two times to work. I already did a lot of researche but none of those solutions helped. Here is my code:
This is how I define the button:
<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" />
It is a button in a Recycler View Cell
. And here is how I set the OnclickListener
method in my Adapter! - Not Aktivity or Fragment: (I already defined this button in the adapter)
mAddButton = (Button) itemView.findViewById(R.id.add_to_list_button);
Here is the onBindViewHolder
method
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);
}
});
I wish you guys could help me Identify the problem. I had been working on this for two days. Thank you so much for your help.