0 votes

How to modify a textView in Android via a button?

As I can modify a text View from a button, example a calculator that when you give to the zero must put zero in screen osea in the text view.


In the onCreate of your Activity you can do the following:

final Button button = (Button) findViewById(R.id.button_id);
final TextView label = (Label) findViewById(R.id.label_id);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        //Si quieres poner el mismo valor que el texto del botón
        //Si quieres agregarle al valor del texto del Label el texto del botón
        // label.setText(label.getText()+v.getText());
        //Si quieres ponerle un texto predeterminado "0"
        // label.setText("0");
        //Si quieres agregarle un texto predeterminado "0"
        // label.setText(label.getText()+"0");


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: