Leviathan
Leviathan

Reputation: 656

<Switch> onClickListener different events whether text or switch is clicked

In one of the screens, the user has to Accept the Terms.
If he clicks on the button of the switch, the terms are accepted. But if he clicks the text left to the button, I actually just want to display the terms (I have a BottomSheet Behaviour for this), without the switch being activated.
So the question is kind of silly, but I actually don't know how to target the text inside the switch.

<Switch
                android:id="@+id/some_id"
                style="@style/Body"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/some_resource1"
                android:layout_marginTop="@dimen/some_resource2"
                android:layout_marginEnd="@dimen/some_resource2"
                android:layout_marginBottom="@dimen/some_resource1"
                android:text="@dimen/some_text_resource"
                app:layout_constraintTop_toBottomOf="@+id/some__different_id" />

This ofc targets the entire switch:

some_id.setOnClickListener {
            myBtmSheetBhvrMethod(SomeFragment())
        }

So what I'd like is something like some_id.text.setOnClickerListener or getting what exactly is clicked during the click event, but since the text has no id I don't know how to achieve this

Upvotes: 0

Views: 27

Answers (1)

Abhimanyu
Abhimanyu

Reputation: 14857

The text on the switch denotes it as the switch label.
For your use-case, a better approach would be to set switch text as an empty string and use a text view or button for showing the terms and conditions text.

Upvotes: 1

Related Questions