package com.example.buttonapp;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
public class MainActivity extends Activity {
OnClickListener listener1=null;
OnClickListener listener2=null;
Button button1;
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listener1=new OnClickListener(){
public void onClick(View v){
setTitle("Button1点击后不见了!");
button1.setVisibility(View.INVISIBLE);
button2.setVisibility(View.VISIBLE);
}
};
listener2=new OnClickListener(){
public void onClick(View v){
setTitle("button2点击后不见了!");
button1.setVisibility(View.VISIBLE);
button2.setVisibility(View.INVISIBLE);
}
};
setContentView(R.layout.activity_main);
button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(listener1);
button2=(Button)findViewById(R.id.button2);
button2.setOnClickListener(listener2);
}
}
原文:http://www.cnblogs.com/mqx365/p/4619978.html