Jason Axelrod Jason Axelrod - 4 years ago 76
Android Question

Two Texts on a Single Button in Android?

I have a button in Android Studio:

<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Event Name (23)" />


It looks like this:

-------------------------------------
| Event Name (23) |
-------------------------------------


What I would like is two pieces of text in a single button.

Basically, I want on the left side of the button, the name of an event... then I want on the right side of the button to have the number of people registered for the event, so it looks like this:

-------------------------------------
| Event Name (23) |
-------------------------------------


Is something like this possible?

I am completely new to Android, so keep that in mind.

Answer Source

You can create Layout instead of Button and Then perform click event on layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="15dp"
    android:id="@+id/relLayout">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Event Name"
        android:layout_alignParentLeft="true"
        android:textSize="16sp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="(23)"
        android:textSize="16sp"/>

</RelativeLayout>

In Activity :

RelativeLayout relLayout = (RelativeLayout) findViewById(R.id.relLayout);

        relLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Implement Your login on RelativeLayout click
            }
        });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download