I am struck at a point in my app. I have 50 buttons on my app. I want to show a text as long as a button is pressed and hide it on its release. Also, on pressing another button, the text should change and hide on its release, and so on. The position of the text remains the same. (Also, can we set a position of the text using X and Y co-ordinates?)
Below is my XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/NUMBERS"
android:textColor="#ecaa00"
android:textSize="28sp"
android:padding="10dip"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="3dip">
<Button
android:id="@+id/one"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/ONE" />
<Button
android:id="@+id/two"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/TWO" />
<Button
android:id="@+id/three"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/THREE" />
<Button
android:id="@+id/four"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/FOUR" />
<Button
android:id="@+id/five"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/FIVE" />
</LinearLayout>
</LinearLayout>
PS: There are many buttons and setting visible properties to each and every button and hiding them on release would take numerous lines of codes. Is there a better way to achieve the same? For example referencing the button which, on pressed shows the text and hides on release.