1
所以,我开发了一个应该作为按钮工作的android小部件。我使用这里给出的基本代码:http://developer.android.com/guide/topics/appwidgets/index.html 单击按钮时,将启动一个活动。这每次都很好!但是,当我记录点击按钮的时间时,我只能第一次得到它。为什么会发生?Android小部件onUpdate()
这里是有人问我的代码:
public class ExampleAppWidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
Log.d("myButton","This is only called once.Why????????")
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_layout);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
没有看到你的代码,这不能回答。 – 2012-02-16 12:55:10
我添加了一些代码。正如我已经提到它只是Android教程 – JustCurious 2012-02-16 13:00:40
Android文档没有功能来改变颜色或类似的东西。因此,您的代码必须与文档有所不同,并且必须以某种方式成为潜在的原因*(并且我们需要查看该部分以帮助您)*。 – 2012-02-16 13:02:11