Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to tap on the Textview the buttons appear/disappear?
    primarykey
    data
    text
    <p>I'm making a program that change the color of the background, for example, when I press white, change background to white, black to black, and so on... and after have pressed a button the others disappear and I have already done that but what I want to do is that each tap on the Textview the buttons appear/disappear. how can I do this? </p> <p>this is my code</p> <pre><code>LinearLayout myLayout; LinearLayout myLayout2; // Declare UI elements private Button firstButton; private Button secondButton, thirdButton; // private ImageView changeBackground; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myLayout = (LinearLayout) findViewById(R.id.myLayout); myLayout2 = (LinearLayout) findViewById(R.id.myLayout2); // Initialize the UI components firstButton = (Button) findViewById(R.id.button1); // When we creating a button and if we expect that to use for event handling we have to set the listener firstButton.setOnClickListener(this); secondButton = (Button) findViewById(R.id.button2); secondButton.setOnClickListener(this); thirdButton = (Button) findViewById(R.id.button3); thirdButton.setOnClickListener(this); } @Override public void onClick(View v) { // Parameter v stands for the view that was clicked. switch(v.getId()) { case R.id.button1: myLayout.setBackgroundColor(Color.WHITE); myLayout2.setVisibility(View.INVISIBLE); break; case R.id.button2: myLayout.setBackgroundColor(Color.BLACK); myLayout2.setVisibility(View.INVISIBLE); break; case R.id.button3: myLayout.setBackgroundColor(Color.RED); myLayout2.setVisibility(View.INVISIBLE); break; } } </code></pre> <p>the xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#A9F5F2" android:id="@+id/myLayout" tools:context=".MainActivity" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="@string/hello_world" /&gt; &lt;LinearLayout android:id="@+id/myLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#D8D8D8" android:orientation="horizontal" android:gravity="center" tools:context=".MainActivity" &gt; &lt;Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/white" /&gt; &lt;Button android:id="@+id/button2" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/button1" android:text="@string/black" /&gt; &lt;Button android:id="@+id/button3" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button2" android:layout_alignBottom="@+id/button2" android:layout_toRightOf="@+id/button2" android:text="@string/red" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload