I have menu xml which included in my activities, im using onClick attribute instead of binding on every startActivity.
My question is, how can I define on the xml onClick attr to call methods which is located on my mainActivity for example?
I thought about something like android:onClick=”mainActivity.doSomething” but its doesnt work.
Using onclick in xml is a bad idea. The fact is it only tries to find the method that the current class is in which is using it. One way to do this IF you really want to do it this way is:
startActivity:
mainActivity:
startActivity.xml:
Your doStuff method must also be static, unless you can get a instance of the target method Activity.