Jump to content

  • Log In with Google      Sign In   
  • Create Account

Android app - basic button functionality


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Ibzy   Members   -  Reputation: 257

Like
0Likes
Like

Posted 27 October 2013 - 11:44 AM

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



Sponsor:

#2 SimonForsman   Crossbones+   -  Reputation: 6306

Like
0Likes
Like

Posted 27 October 2013 - 01:04 PM

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, 27 October 2013 - 01:06 PM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#3 Ibzy   Members   -  Reputation: 257

Like
0Likes
Like

Posted 29 October 2013 - 02:02 PM

Hi Simon,

 

Thanks for this - pointed me in the right direction.  Didn't quite realise how 'separated' the code needed to be.

 

Cheers






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS