I'm pretty sure that you can use the activity's class as long as it
implements View.OnClickListener()  That's how I've been doing it for
awhile now and how I've seen it in at least one of the beginning
android books I've read.

I can't recall offhand if android:debuggable was set to true but
breakpoints have been working and I didn't specifically check to
change that attribute so I assume right now that it works. Also when
you say debug log are you referring to the output of adb logcat?
Because yes I've been using that and nothing came up when I clicked on
the button.

I figured it out in the end though. I had an onResume() in my activity
for when I returned to that activity and reloaded info on it. The 3
other buttons on that page had their onclicklisteners set again in
there but not the fourth button that I just added. I didn't know that
onResume was run when an activity was first started. I thought it was
just when the activity was brought back into the foreground. I also
didn't realise that once the onResume was run it would somehow
'forget' the previous time that the listener was set in onCreate(). So
I just set it a second time in onResume() and it worked.

On Dec 7, 3:55 am, niko20 <[email protected]> wrote:
> Hi,
>
> In the first case you were trying to use the Activity's main view
> OnClick(), this won't work though.
>
> In the second case did you check the debug log? (DDMS debug output)
> that second version writes to the log. Also, in order to debug you
> need to have android:debuggable="true" in your application manifest.
> If you don't it wont stop on breakpoints or anything, you will get an
> error in the log but it may be hard to spot.
>
> -niko
>
> On Dec 6, 11:55 pm, launchpadtt <[email protected]> wrote:
>
>
>
> > Hello,
>
> > I'm currently baffled about something. It seems like a genuine bug in
> > the SDK.
>
> > I have an activity that was the main activity for my program. It
> > consisted of 3 buttons. I added a third using the wysiwyg editor in
> > eclipse
>
> > <Button android:layout_width="wrap_content"
> > android:layout_height="wrap_content" android:id="@+id/buttonauthor"
> > android:text="Also by Author"></Button>
>
> > then I made a variable to refer to it in my activities onCreate() for
> > the activity which implements
>
> >                 whatthehell=(Button)findViewById(R.id.buttonauthor);
> >                 whatthehell.setOnClickListener(this);
>
> > then I made the OnClick Listener toast
>
> >         public void onClick(View view) {
> >                 if (view == whatthehell) {
> >                         Toast.makeText(this, "clicked button02", 
> > 2000).show();
> >                 }
> >         }
>
> > When I ran it, it didn't click. When I debug it, it didn't even go
> > into the onClick method.
>
> > I tried to give it its own anonymous OnClick listener and it did the
> > same behaviour
>
> >                 whatthehell.setOnClickListener(new View.OnClickListener() {
> >                         public void onClick(View v) {
> >                                 // TODO Auto-generated method stub
> >                         Log.v("Clicked the author button", "Pressed the 
> > author
> > button");                  }
> >                 });
>
> > I thought something may have been wrong with the emulator image, but I
> > tried it on a separate installation of Eclipse and had to make a new
> > emulator image for it. and it still did the same thing.
>
> > Am I missing anything?

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to