两个按钮PendingIntents - 小工具 [英] Two buttons with PendingIntents - Widget

查看:123
本文介绍了两个按钮PendingIntents - 小工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个按钮,一个小部件。 他们中的一个来更新小窗口的内容,第二个必须启动的活性。

我有两个PendingIntent每个动作,但我不能让他们两人的工作。如果一个人的工作,另一个没有。

我已经修改了code和无法理解什么是错的。

任何帮助将是非常美联社preciated。

这是在code。

  RemoteViews控件=新RemoteViews(context.getPackageName(),R.layout.miwidget);

    意向意图=新的意图(actony.com.ACTUALIZAR_WIDGET);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,为widgetid);


    意图int​​entSettings =新意图();
    intentSettings.setClass(背景下,WidgetConfig.class);


    PendingIntent pendingIntentUpdate = PendingIntent.getBroadcast(背景下,为widgetid,意向,PendingIntent.FLAG_UPDATE_CURRENT);
    controls.setOnClickPendingIntent(R.id.BtnActualizar,pendingIntentUpdate);

    PendingIntent pendingIntentSettings = PendingIntent.getActivity(上下文,0,intentSettings,0);
    controls.setOnClickPendingIntent(R.id.botonSettings,pendingIntentSettings);
 

解决方案

检查此链接知道哪个按钮被点击时,有两个或一个小部件更按钮。

<一个href="http://stackoverflow.com/a/10733049/1331593">http://stackoverflow.com/a/10733049/1331593

这应该工作...如果它不能正常工作,请让我知道是什么问题...

I'm creating a widget with two buttons. One of them updates the content of the widget and the second one must launch an activity.

I have two PendingIntent for each action, but I can't make them both work. If one works the other one doesn't.

I've revised the code and can't understand what's wrong.

Any help will be very appreciated.

This is the code.

    RemoteViews controls = new RemoteViews(context.getPackageName(), R.layout.miwidget);

    Intent intent = new Intent("actony.com.ACTUALIZAR_WIDGET");
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);


    Intent intentSettings = new Intent();  
    intentSettings.setClass(context,WidgetConfig.class);  


    PendingIntent pendingIntentUpdate = PendingIntent.getBroadcast(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    controls.setOnClickPendingIntent(R.id.BtnActualizar, pendingIntentUpdate);

    PendingIntent pendingIntentSettings =  PendingIntent.getActivity(context, 0, intentSettings, 0);
    controls.setOnClickPendingIntent(R.id.botonSettings, pendingIntentSettings);

解决方案

Check this link to know which button has been clicked when there is two or more button in a widget..

http://stackoverflow.com/a/10733049/1331593

It should work... IF it does not work please let me know what is the problem...

这篇关于两个按钮PendingIntents - 小工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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