0

I am creating a RecyclerView on a fragment, and there is a button in one of the viewHolder(cell). But on the emulator, nothing happened after I clicked on that button. I set break points in the code for onClickListener, it doesn't even jump into the breakpoint.

Here is how I implement the button in the layout file:

<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:text=""
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

Here is my code in the adapter:

Button mAddButton

mAddButton = (Button) itemView.findViewById(R.id.add_to_list_button);
mAddButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.d("test button","testinbtn");
        AddContactToList(GlobalPosition);
    }
});

private static void AddContactToList(int pos) {
    String list_id = mUnsubscribedList.get(pos - 2 - mSubscribedList.size()).getList_id();
    apiInstance.AddContactToTheList(contact.getContactID(), list_id);
}

I had checked the resource ID, the resource ID is correct. I had cleaned the project, rebuild the project, quite and relaunch Android Studio.

Jacky.S
  • 364
  • 5
  • 17
  • Just eliminating other posibilities, you don't have any other buttons named `add_to_list_button` elsewhere? And it's definitely the correct layout you're inflating? What happens when you set another property on `mAddButton` e.g. `setEnabled(false)`? – Michael Dodd Jul 06 '18 at 21:02
  • Can you post the whole adapter code? And have you tried something else, like changing the text of your button from your adapter? – Anis LOUNIS aka AnixPasBesoin Jul 06 '18 at 22:23

0 Answers0