如何present举杯一个widget被点击? [英] how to present a toast when a widget is clicked?

查看:136
本文介绍了如何present举杯一个widget被点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一个简单的小工具,$就可以了一下当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 的onClick()法>

更新:

如果您使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆