我正在创建一个用于学习目的的模拟时钟小部件,并且想知道如何进行设置布局以更改时钟表盘图像。我已经完成了小部件,但我似乎无法获得 onclicklstener 来调出设置布局。
这就是我所拥有的:
@Override
public void onDeleted(Context context, int[] appWidgetIds)
{super.onDeleted(context, appWidgetIds);
}
@Override
public void onDisabled(Context context) {
super.onDisabled(context);
}
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
{
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
Intent AlarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.android.alarmclock", "com.android.alarmclock.AlarmClock"));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, AlarmClockIntent, 0);
views.setOnClickPendingIntent(R.id.Widget, pendingIntent);
AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views);
}
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds)
{
super.onUpdate(context, appWidgetManager, appWidgetIds);
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.settings);
Intent launchActivity = new Intent(context,Widget.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context,0, launchActivity, 0);
updateViews.setOnClickPendingIntent(R.id.Widget, pendingIntent);
ComponentName myComponentName = new ComponentName(context, Settings.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(myComponentName, updateViews);
}
}