4
\$\begingroup\$

I want to open an AlertDialog on the click of either a Button or TextView but I am not sure what would work best. When a selection is made in the AlertDialog, I want the bottom text to be updated with the selection. Here are the two options I have:

TextViews only. Here, the LinearLayout will have listener and will open AlertDialog.

<LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/label"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Label" />

    <TextView
        android:id="@+id/selection"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginStart="5dp"
        android:textSize="18sp"
        android:text="Select..." />

</LinearLayout>

TextView and Button. Here, the Button will open the AlertDialog and the text inside the Button will be replaced with the selection.

<TextView
    android:id="@+id/label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="5dp"
    android:layout_marginStart="5dp"
    android:text="Label"
    android:textSize="16sp"
    android:textColor="@android:color/white" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/label"
    android:layout_marginTop="-20dp"
    android:text="Select..."
    android:textAllCaps="false"
    android:textColor="@android:color/white"
    android:gravity="start|center_vertical"
    android:paddingLeft="15dp"
    android:paddingStart="15dp"
    android:paddingRight="15dp"
    android:paddingEnd="15dp"
    android:paddingTop="15dp"
    android:textSize="18sp"
    android:background="@android:color/transparent" />
\$\endgroup\$
0
\$\begingroup\$

Answer is Button.

Button is a subclass of TextView. So it has all the features of TextView and additional features of Button class. Button adds a few stylistic changes (e.g., default background image, additional padding, ripple effect) to allow quicker adaptation to your designs.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.