Android_组件的显示与隐藏

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;



public class HhActivity extends Activity {

  

    Button but1 = null;

    Button but2 = null;

    TextView text1 = null;

    EditText edit1 = null;



    @Override

    public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

       but1 = (Button) findViewById(R.id.but1);

       but2 = (Button) findViewById(R.id.but2);

       text1 = (TextView) findViewById(R.id.text1);

       edit1 = (EditText) findViewById(R.id.edit1);

       but1.setOnClickListener(new OnClickListener() {



           @Override

           public void onClick(View v) {

              // TODO Auto-generated method stub

              but1.setVisibility(View.GONE);

              but2.setVisibility(View.VISIBLE);

              text1.setVisibility(View.VISIBLE);

              edit1.setVisibility(View.VISIBLE);

           }

       });

       but2.setOnClickListener(new OnClickListener() {



           @Override

           public void onClick(View v) {

              // TODO Auto-generated method stub

              but1.setVisibility(View.VISIBLE);

              but2.setVisibility(View.GONE);

              text1.setVisibility(View.GONE);

              edit1.setVisibility(View.GONE);

           }

       });

    }

}





你可能感兴趣的:(android)