Method analysis of Android implementation referencing custom view in XML file

This article gives an example of how Android implements the method of referencing a custom view in an XML file. Share with you for your reference, as follows:

Reference custom view in XML

Method 1:

Method 2:

This error was encountered while referencing the custom view in the XML file:

Java.lang.RuntimeException: Unable to start activity ComponentInfo{cm.test/cm.test.TestsActivity}: Android.view.InflateException: Binary XML file line #8: Error inflating class com.test.testview

This requires checking whether the package name is correct when referenced in XML

You may also encounter this error: 11-24 10:58:38.993: error / androidruntime (323): caused by: java.lang.nosuchmethodexception: helloview (context, attributeset)

This is because a constructor is missing from the custom view

More readers interested in Android related content can view the special topics of this site: summary of Android view skills, summary of Android layout skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solutions, summary of Android basic component usage and summary of Android control usage

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>