How to provide input to textview in Android Studio?

Text View :

Text View is the View in the Android , that is used to show text in the Android User interface . These text Views are used to Display some information to the user about any other related components in the android .

In Andorid Studio you can set the text in the Text View in the two following ways .

A.  By Editing the Xml part of the Text View . 
B.  By Editing the Android java Code class , or Kotlin code .

A . By Specifying XML .

1. in your XML part of your View UI just navigate to your text view section .
2. Add the line ( " android : text = "Sample Text You want to enter " " )
3. if you want to give refrence to your String File you can do it like ( " android : text = "@String/my_string" " )
4.this will just set the text for your text view in the android studio . and successfully run on android . 

if in case you want to change the text in the middle of your application state you have to follow the method B .

B. By JAVA CODE class file .

1. first go to your XML part of your UI text view , and provide a id for it as like ( " android : id = " + id / demo_id " " )
2. no go to your java class of the UI file .
3. Create a variable of text view just like below in your class:

TextView mtextView ;

4. now you have to initiate the mtextView that you have created with refrence to the that you have provided to the textView in your XML file just like this :

mtextView =  ( TextView ) findviewbyid ( R.id.demo_id ) ; 

5. now you have to use the settext method of your textView to set the text to it :

mtextView.setText("StringText");

6. if you want you can refrence the text to the String file using String converter as follows :
 
mtextView.setText(String.valueof(R.String.my_string));

7. Run the app to have the UI updated ;
 

Comments