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