My TextSwitcher class extends view. How can I add it in to my main file and envoke methods in the class?
Ive tried:
addView(new TextSwitcher(this));
But no luck.
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.
By “my main file”, you mean the main layout file? First, you can do that straight in the layout XML. The syntax is:
and don’t forget width/height/weight/etc.
Second, you can add it programmatically via
addView(). Be careful to pick the right container object for that. And don’t forget to set its layout params, which must be compatible with the container (for objects in LinearLayout, you provide params as as instance of LinearLayoutParams, etc.).I recommend the first approach though. Layout params are not particularly code-friendly, especially if you want density-independent sizing.