How to set text for a TextView in Android using Android Studio
How to set text for a TextView in Android using Android Studio.
Example :
On button click set text for TextView:
In Java:
Step1:
Declare String, TextView
private String name="Tech Uplift";
private TextView textView;
Step 2:
Declare TextView in onCreate method.
Step3:
In on Click Method set like this:
private void changeText(){
//this is the line that sets the text to the TextView
textView.setText(name);
}
In Kotlin:
Step1:
Declare String, TextView
val name: String
name="Tech Uplift"
TextView textView
Step2:
Declare TextView in onCreate method (optional)
Step3:
In on Click Method set like this:
fun changeText(){
//this is the line that sets the text to the TextView
textView.text=name
}
*in Kotlin semicolon operator not required.
Example :
On button click set text for TextView:
In Java:
Step1:
Declare String, TextView
private String name="Tech Uplift";
private TextView textView;
Step 2:
Declare TextView in onCreate method.
Step3:
In on Click Method set like this:
private void changeText(){
//this is the line that sets the text to the TextView
textView.setText(name);
}
In Kotlin:
Step1:
Declare String, TextView
val name: String
name="Tech Uplift"
TextView textView
Step2:
Declare TextView in onCreate method (optional)
Step3:
In on Click Method set like this:
fun changeText(){
//this is the line that sets the text to the TextView
textView.text=name
}
*in Kotlin semicolon operator not required.
Comments
Post a Comment