English 中文(简体)
OnClick和AlarmManager一起为我赢得了工作。
原标题:OnClick together with AlarmManager in widget wont work for me

I have a Widget that I update using a AlarmManager and it works fine.

我现在要补充一次关于Click事件。 我的问题是,我从来都不会被点火? 或由我的退休者处理。

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// TODO Auto-generated method stub
 super.onUpdate(context, appWidgetManager, appWidgetIds);

 final int N = appWidgetIds.length;
      for (int i=0; i<N; i++) {
          int appWidgetId = appWidgetIds[i];
          updateAppWidget(context, appWidgetManager, appWidgetId);

          //Toast.makeText(context, "onUpdate(): " + String.valueOf(i) + " : " + String.valueOf(appWidgetId), Toast.LENGTH_LONG).show();
      }

}

public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId){
.
.
.
RemoteViews updateViews = new RemoteViews(context.getPackageName(),R.layout.widget_layout);

updateViews.setTextViewText(R.id.widgettext, "[" + String.valueOf(appWidgetId) + "]" + strWidgetText);


Intent intent = new Intent(context, MyWidgetProvider.class);
intent.setAction(MY_WIDGET_CLICK);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,1, intent, 0);

updateViews.setOnClickPendingIntent(R.id.toggle_button_widget, pendingIntent);  
appWidgetManager.updateAppWidget(appWidgetId, updateViews);

我也希望这样做。

public void onReceive(Context context, Intent intent) {
 // TODO Auto-generated method stub
 super.onReceive(context, intent);

 if(MY_WIDGET_UPDATE.equals(intent.getAction())){

   Bundle extras = intent.getExtras();
   if(extras!=null) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName thisAppWidget = new ComponentName(context.getPackageName(), MyWidgetProvider.class.getName());
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);

    onUpdate(context, appWidgetManager, appWidgetIds);
   } else if (MY_WIDGET_CLICK.equals(intent.getAction())) {
       Toast.makeText(context, "onClick()", Toast.LENGTH_LONG).show();
   }

 Toast.makeText(context, "onReceiver()" + intent.getAction(), Toast.LENGTH_LONG).show();
 }
}

你们可以看到,我有一位名叫Alarm的传言,我只拿MY_WIDGET_UPDATE作为行动。

And the Manifest

        <receiver android:name="company.se.MyWidgetProvider" android:label="News Nobwidget">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                            </intent-filter>

            <intent-filter>
                <action android:name="MY_OWN_WIDGET_UPDATE" />
                <action android:name="MY_OWN_WIDGET_ONCLICK" />
            </intent-filter>

            <meta-data android:name="android.appwidget.provider"
                android:resource="@xml/widget_info" />
        </receiver>

        <activity android:name="company.se.HelloWidgetConfig" android:label="Hello Widget Config">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>


    </application>
    <uses-sdk android:minSdkVersion="10" />

</manifest>

我的“安乐”非常新,因此任何帮助都受到赞赏;

我猜测,我的讲话过滤了Click事件。 是否有任何人知道,你能看到哪些事件引发激烈的Eclipse夸张?

页: 1

最佳回答

St!

Bug发现,它没有任何灵丹妙药,只好坏方案规划。

I had the else if (MY_WIDGET_CLICK.equals(intent.getAction()) nested with if(extras!=null) instead of if(MY_WIDGET_UPDATE.equals(intent.getAction()))

因此,该法典的其他部分发挥作用! 我希望我把任何人混为一谈。

页: 1

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签