> I'm trying to develop my first home screen widget for android, but
> don't know how to use buttons. I've followed the tutorial
> http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html
> but it doesn't show how to use buttons. Somewhere I read about
> RemoteViews, PendingIntents and the setOnClickPendingIntent method,
> but I don't really know how to use them.
> Therefor, I have some questions:
> 1) How do I set an onClickListener (or an OnClickPendingIntent() ) for
> the button?

In the tutorial you cite, Jeff Sharkey uses setOnClickPendingIntent() for
clicks on the widget as a whole. However, that works just as well for
clicks just on a button -- provide the button's ID as the first parameter.

>     1,2) where do I set this? There is no onCreate() method..

You would set it wherever you are building your RemoteViews.

> 2) This method starts an Intent, but how do I use an Intent to just
> run a method? I do not want to start any activity.

You can't use an Intent to "just run a method". However, an Intent does
not need to start an activity. Jeff's example uses
PendingIntent.getActivity() to launch an activity, but you could use
PendingIntent.getService() or PendingIntent.getBroadcast() to communicate
with other components.

I can point you at some source code for an app widget that demonstrates
the use of buttons communicating with a back-end service -- visit:

http://commonsware.com/AdvAndroid/

and download the source code to my one book. In the ZIP file, you will
find an AppWidget/TwitterWidget project. As the name suggests, it is a
widget that displays the latest tweet in your friends' timeline. It also
has a button to refresh and a button to configure the widget. The
configure button pops an activity, but the refresh button triggers the
same logic as is invoked when updateTimeMillis elapses.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~---------~--~----~------------~-------~--~----~
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