如何present举杯一个widget被点击? [英] how to present a toast when a widget is clicked?
问题描述
我需要做一个简单的小工具,$就可以了一下当p $ psents敬酒。
我的问题是,我无法找到如何获得或创建的OnCreate行动。我看到与打开的网络浏览器的未决意图的实施例。但如何简单地创建这样的: Toast.makeText(背景下,激活,Toast.LENGTH_LONG).show();
,并使其发生在用户每次点击的时间小部件?
只是要清楚,我的意思是在手机的发射窗口小部件。不是一个普通的按钮窗口小部件等......
公共类的Widget扩展AppWidgetProvider {
NotificationManager mNotificationManager;
通知通知;
@覆盖
公共无效的OnUpdate(上下文的背景下,AppWidgetManager appWidgetManager,INT [] appWidgetIds){
super.onUpdate(背景下,appWidgetManager,appWidgetIds);
appWidgetManager.updateAppWidget(appWidgetIds,视图);
}
}
谢谢!
只需拨打 Toast.makeText(背景下,激活,Toast.LENGTH_LONG).show();
在 View.OnClickListener
更新:
如果您使用 AppWidgetProvider
所以请这和<一href="http://stackoverflow.com/questions/2471875/processing-more-than-one-button-click-at-android-widget">this 之一的帖子
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!
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
这篇关于如何present举杯一个widget被点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!