android-studio Button按钮使用

.xml部分




    

.java部分

package com.example.administrator.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity{
    private Button myBtn_one;
    private Button myBtn_two;
    @Override
    protected  void  onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myBtn_one = (Button) findViewById(R.id.btn_one);
        myBtn_two = (Button) findViewById(R.id.btn_two);
        myBtn_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myBtn_two.setText("按钮2已被点击");
            }
        });
    }
    public void click(View v){
        myBtn_one.setText("按钮1已被点击");
    }
}

你可能感兴趣的:(Android开发)