Sign in to follow this  

Android app - basic button functionality

This topic is 1504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All,

 

I am working on an Android app, and am just learning to program on Android.  I have experience in a few programming languages, but I'm struggling to combine functionality across xml and java.

 

Very simple question I'm sure, but how do I make a button activate a function?  I have: "public void function(string a, string b)" with the function inside in Java, and on the xml layout I have <Button android:onClick="function(stringa, stringb)".

 

When I click the button i get an error saying it cannot locate method "function(stringa, stringb)".

 

Thanks

Share this post


Link to post
Share on other sites

IIRC you have to specify a method that takes a View as its only parameter in the XML file.

 

so your method should be:

 

public void someMethod(View v) {

...code

}

 

and then in the xml layout:

 

<Button blaha blaha ....

android:onClick="someMethod" /> (only the method name, no parameters)

 

Your on click method also has to be a member of the current Activty.

Edited by SimonForsman

Share this post


Link to post
Share on other sites

This topic is 1504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this