Make Android TextView invisible before clicking a button?

I want to make TextView invisible until a button is clicked. In particular, they answer the question and are visible only after clicking the button under it.

What am I still →

public class AndroidAssignment2_1 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_android_assignment2_1); Button next = (Button) findViewById(R.id.QButton); next.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent intent = new Intent(); setResult(RESULT_OK, intent); finish(); } }); Button next1 = (Button) findViewById(R.id.QButton); next1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(), AndroidAssignment2_2.class); startActivityForResult(myIntent, 0); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.android_assignment2_1, menu); return true; } } 

xml for this class

 <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" > <TextView android:id="@+id/Questions" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="0dip" android:text="@string/Q2" /> <Button android:id="@+id/QButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_question" /> <Button android:id="@+id/AButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" /> <TextView android:id="@+id/Answers" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="0dip" android:hint="@string/A2" /> <Button android:id="@+id/QuitButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_quit" /> </LinearLayout> 

I don't think it takes more, I'm just looking for code that I would apply to "AButton" to make the TextView "Responses" visible only after the user clicks it.

+8
java android android-layout
source share
3 answers

XML:

 <TextView android:id="@+id/Answers" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="0dip" android:hint="@string/A2" android:visibility="invisible"/> 

the code:

 Button button = (Button) findViewById(R.id.AButton); button.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { TextView tv = AndroidAssignment2_1.this.findViewById(R.id.Answers); tv.setVisibility(View.VISIBLE); } }); 
+15
source share

To do this, you first need to create a TextView, write our message in it, and make the TextView invisible using the visibility property if the Textview looks like this:

 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" **android:visibility="invisible"**/> 

and then create a method in your main activity class to display an uninteresting test view in our layout using the setVisibility () method, for example:

  public void onLoveButtonClicked(View view){ TextView textView = (TextView) findViewById(R.id.haikuTextView); textView.setVisibility(View.VISIBLE); } 
+3
source share

Sets the visibility of TextView Answers to be invisible or default.

Find the AButton button in the same way as the other button views.

Set onClickListener to the AButton button, like other button listeners that do two things:

Find TextView Answers the same way you find button views.

Call setVisibility in TextView responses.

0
source share

All Articles