在按下按钮之前使Android TextView不可见?

Lea*_*ode 8 java android android-layout

我希望在按下按钮之前使TextView不可见.具体来说,它们是问题的答案,只有按下它下面的按钮才能看到.

到目前为止我所拥有的>>

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;
    }

}
Run Code Online (Sandbox Code Playgroud)

这个类的xml

<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>
Run Code Online (Sandbox Code Playgroud)

我不认为需要更多,我只是寻找我将应用于"AButton"的代码,使TextView"Answers"只有在用户点击后才可见.

has*_*san 15

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"/>
Run Code Online (Sandbox Code Playgroud)

码:

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);
    }
}); 
Run Code Online (Sandbox Code Playgroud)