Created
June 25, 2021 10:51
-
-
Save extsalt/901d784b929b79664747433d46088d6b to your computer and use it in GitHub Desktop.
Android Button On Click Listener and TextView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mycalculator; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
EditText num1, num2; | |
TextView textView; | |
Button button; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//1 | |
setContentView(R.layout.activity_main); | |
Log.d("ON_CREATE", "called"); | |
button = this.findViewById(R.id.button); | |
textView = this.findViewById(R.id.textView); | |
button.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(getApplicationContext(), "Hello world", Toast.LENGTH_SHORT) .show(); | |
textView.setText("hello world"); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment