Skip to content
Advertisement

How to Call function in custom view in android studio activity

MainActivity.java

JavaScript

CustomView.java

JavaScript

activity_main.xml

JavaScript

when I going to run that code in my device it keep closing. Log cat shows error like this.

JavaScript

I use physical device to implement this code. I’m beginner android developer also. I follow different kind of tutorials but I could not be able to solve it.I want to use this custom component same as normal widgets like buttons,Edit Text.I also want to place this code using xml also. I cannot able to change it. because my target project is already developed using xml layouts. How can I solve it ?

Advertisement

Answer

The problem is that you are not passing the attrs to the super. This causes it to not have an id

Change your constructor to

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement