Android:onclick = "functionname" Did Not Recognize The Function Name In Fragment Subclass
Solution 1:
Thats not an error. (The method warning, not the app crashing). The Java compiler doesn't know you've defined the listener in the XML, so since you never explicitly call those methods, it simply thinks that they are "never used"
Personally, I always setOnClickListener on my views from the Java code
Solution 2:
When Android is running and checking for onClick methods, it only looks in the main Activity class. You cannot put an onClick method in a fragment. Fragments are not the same as activities, so they should not be abused.
Another question has the same problem here: https://stackoverflow.com/a/39429157/6754053
Solution 3:
Removing this line from your layout's root might help;
tools:context=".MainActivity"
Solution 4:
As other users said. you cannot use onClick
attribute with Fragments. But this universe has Jake Wharton and his awesome libraries including Butterknife. Check this out.
Post a Comment for "Android:onclick = "functionname" Did Not Recognize The Function Name In Fragment Subclass"