Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

android - how to present a toast when a widget is clicked?

I need to do a simple widget that presents a Toast when clicking on it. My problem is that I cant find how to get or create an "oncreate" action. i see the examples with the pending intent that opens the web browser. But how do i simply create this: Toast.makeText(context, "activated", Toast.LENGTH_LONG).show(); and make it happen every time a user clicks on the widget? just to be clear, I mean a widget on the launcher of the phone. not a regular "button" widget etc...

public class Widget extends AppWidgetProvider {
NotificationManager mNotificationManager;
Notification notification;

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);



    appWidgetManager.updateAppWidget(appWidgetIds, view);
}

}

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just call Toast.makeText(context, "activated", Toast.LENGTH_LONG).show(); in widget's onClick() method of View.OnClickListener

Update:

If you use AppWidgetProvider so check this and this one posts


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...