Reputation: 11146
I have defined an App Widget (AppWidgetProvider
, etc.), and I want to write an ad hoc program for the onClick
of one of the buttons in the App Widget. The documentation describes how to inflate a layout for the App Widget and how to set a particular action on a button (see RemoteViews.setOnClickPendingIntent()
), but I don't see a way to write an ad hoc OnClickListener
() for the button in the way that we do for buttons in Activities.
Upvotes: 1
Views: 7722
Reputation: 24031
If you are asking how to call method from another class then make that method static and if not then elaborate your question.
And if you are asking for how to set the OnClicklistener over widget then try this:
Yourbutton.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
}
};
Upvotes: 1
Reputation: 1703
Short answer: you can't. App Widgets are lightweight -- Android does not want App Widgets to run ad hoc code because that code could slow down the App Widget framework. Instead, AppWidgetProviders are supposed to do the work of App Widgets. The communication between AppWidgetProvider and AppWidget is a) the provider can update the widget with a new layout and b) the elements of that layout can send intents, which the AppWidgetProvider or other Android components can intercept and process.
See Adding behavior to individual items for an example of the AppWidgetProvider defining a custom Intent that it intercepts from its App Widget.
@Shubh: I edited your original question to make it clearer -- if you like the edit, you'll need to permit the edit so that others can see it.
Upvotes: 1