While writing an Android App, when I use TextView in different class(MyClass) other than the main class,
I’m getting an error:
The method findViewById(int) is undefined for the type MyClass
Please tell me the point I’m missing.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
MyClassdoesn’t extend androidsActivityclass, therefore you don’t have that method available. So you have to get a reference to use it, preferably through a method argument (never store a activity/context reference in a class member variable, it might result in a memory leak):Small sample:
And in MyClass