Android custom view derived class

Source: Internet
Author: User

There are two implementation methods for Android UI: one is to directly hardcode the UI in the code, and the other is to layout the UI in XML. Because I need to draw some curves on The View, the view class is derived directly. You can use setcontentview (New customeview () to draw lines normally. Finally, when I put the derived classes of views such as customeview and Other Android built-in textview in XML, I set the UI of the activity through setcontentview (resourceid, the customeview class cannot be found on the Virtual Machine in logcat during runtime. The final result is to add the entire package name (as shown in red) to the XML, because the custom derived class is no longer in the classpath of the Java Virtual Machine.

 

<Com. Practice. fundtest.
Customeview
Android: Id = "@ + ID/fundview"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
/>

 

When the customeview class can be loaded normally, I want to get the Instance Object of customeview in the form of findviewbyid, but every time the findviewbyid class returns NULL. You can use findviewbyid to find the view object that comes with Android to get it correctly. Therefore, you can see whether the id value is not passed to the customeview instance when inflate XML in setcontentview, finally, we found that many attributes in XML are passed through the second parameter in the view constructor view (context, attributeset ATTR, however, my Derived classes only provide customeview (context) functions, so that the id value cannot be passed in. findviewbyid returns NULL.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.