*
The moose likes Android and the fly likes onClickListener of button does not work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "onClickListener of button does not work" Watch "onClickListener of button does not work" New topic
Author

onClickListener of button does not work

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
I am VERY new to Android so this might be silly issue for experts. Here is my code,



When I click on button, nothing happens neither on screen nor on console. I have put few debugging statements, They do not execute either. Though app screen loads properly with all UI components.
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1087
you didn't impliment the OnClickListener
zoheb hassan
Ranch Hand

Joined: Apr 01, 2009
Posts: 150

Saurabh you did implement the OnClickListener as an anonymous class and the click just works fine.The only problem here is that you are running it on an android 2.2 emulator since you will be launching an google map you should run it on an emulator which has one and you should do this by installing google api 2.2 platform and creating an emulator for it.I have run the same code you put here on an google api 2.2 emulator and it works just fine

Best Regards,
Zoheb
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
zoheb hassan wrote:Saurabh you did implement the OnClickListener as an anonymous class and the click just works fine.

How do you figure that? The post states that the logging statements are not being executed - so the button click does not "work just fine". Furthermore, how do you infer that code runs on Android 2.2, or in an emulator? None of that is mentioned in the post.
Vishal Trivedi
Ranch Hand

Joined: Sep 05, 2011
Posts: 57
whats the point of using System.out.println() for android you can use Log??
zoheb hassan
Ranch Hand

Joined: Apr 01, 2009
Posts: 150

How do you figure that? The post states that the logging statements are not being executed - so the button click does not "work just fine".


Hey Tim well i did mention that i ran the code myself and the log statements do execute fine unless he tied his OnClickListener to an another button which may not be the case and the implementation however was right i.e., listening for a button click and firing an intent. Looking at the code one can infer that the guy was using an EdiText to take an input location and on click of an button wanted to display on map the location the user Input.

What i am not clear tough is whether you were asking a question or asserting the above statement

Secondly

Furthermore, how do you infer that code runs on Android 2.2, or in an emulator? None of that is mentioned in the post.


Because the only place this code would fail is on an android emulator with no google apis.If the same code was being run on an actual device or an emulator with google api it would not fail and hence the statement was made.His implementation or the code was all right only issue here was running it on an emulator not meant for it

-zoheb
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
i ran the code myself and the log statements do execute fine

Well, we don't know what code you ran, but we have to believe Saurabh Pillai when he says that his code is not logging anything, and thus does not work fine. (And no, I'm not asking, I'm making a statement.)

Because the only place this code would fail is on an android emulator with no google apis.

The code appears not even to run, so it's too early to make assumptions about why it fails. There are plenty of devices that do not have the Google APIs, by the way, not just the emulator. Those devices *may* have other software that knows what to do with a "geo:" URI, or they may not. (And I still don't see where the "Android 2.2" comes from.)

As a general rule, I'd put an @Override annotation before each method that is supposed to override (or implement) a superclass (or interface) method. That habit will save you lots of time, even if it's not the problem here.
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Hello Guys,

Zoheb was right. I was running it against Android emulator as opposed to Google API emulator. I changed it to proper emulator and it works just fine.

Also, I was wrong about logging-statements-not-being-printed or I should say I was looking at the wrong place. I was looking at Console opposed to LogCat. But I did not know anything about DDMS when I posted this question. I read about it now and now I know something.

But it is really frustrating that emulator take really long (10 minutes for Google API level 8 emulator). How long does it take for you guys?

Thank you for your inputs.
zoheb hassan
Ranch Hand

Joined: Apr 01, 2009
Posts: 150

Well Saurabh glad that the posts were helpful in figuring out what the problem was.As for looking at the wrong places you figured where to look for them that's another step forward.Good luck in developing your app and do let us know when you publish it to the market and as for emulator it does take frustratingly long for it to get started don't worry about it just leave it on once you begin for the day and close it when only when you are done with it or you can get a android device.

Best Regards,
Zoheb
 
 
subject: onClickListener of button does not work