单击按钮时设置Android TextView的值

use*_*675 0 java android textview settext

在Java中,如果我想JLabel在单击a时设置a的值JButton,我可以像这样编码...

JButton button = new JButton("add");
JButton label = new JLabel();

public void addListenersToButtons(){
    button.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == button) {
        label.setText("this is the number = " + number);
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望能够在Android中执行类似的操作,我在其中设置TextField用户单击按钮时的值.Android中适当的代码是什么?

Akh*_*ran 5

这是一个例子:

    final Button btn = (Button) findViewById(R.id.btn);

    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            TextView tv = (TextView) findViewById(R.id.TextView1);
            tv.setText("hellooo");
        }
    });
Run Code Online (Sandbox Code Playgroud)