How do I make views varibles (android) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do I make views varibles (android)

I have tried making a text view a varible so that I can use it in functions latter (using the command work= findViewById(R.id.txt) ) but this is not working- it is saying that whatever the name of the varible is (work) can not be resolved into a varible. How do I fix this?

12th Nov 2020, 4:48 AM
Cam UOR
Cam UOR - avatar
5 Answers
+ 7
Cam UOR - For EditText, Textview and any other text Fields : Getting texts i.g work.getText(); : Set text i.g work.setText("yes");
12th Nov 2020, 5:55 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 6
Java is strongly typed language, So you need to declare variables type first, i.g TextView work= findviewbyid (R.id.txt);
12th Nov 2020, 5:15 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 2
Thank you ah very mych
12th Nov 2020, 5:55 AM
Cam UOR
Cam UOR - avatar
+ 1
TextView textView = (TextView) findviewbyid(R.id.text);
12th Nov 2020, 9:57 AM
Nitin Gutte
Nitin Gutte - avatar
0
Ah thanks. Would you also know how to access the text part E.g. Work.android.text ="yes"
12th Nov 2020, 5:42 AM
Cam UOR
Cam UOR - avatar