根据月份显示Widget ImageView
Display Widget ImageView based on month
我有 12 张图像保存在 drawable 中,文件名根据月份命名,即 jan、feb、mar、apr 等。如何根据当前在 Android 小部件的 ImageView 中显示图像月?例如,当前是四月,则应显示文件名为 apr 的图像。
我正在关注 https://looksok.wordpress.com/2012/12/15/android-complete-widget-tutorial-including-source-code/
的教程
public class MyWidgetIntentReceiver extends BroadcastReceiver {
private static int clickCount = 0;
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("pl.looksok.intent.action.CHANGE_PICTURE")){
updateWidgetPictureAndButtonListener(context);
}
}
private void updateWidgetPictureAndButtonListener(Context context) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_demo);
remoteViews.setImageViewResource(R.id.widget_image, getImageToSet());
//REMEMBER TO ALWAYS REFRESH YOUR BUTTON CLICK LISTENERS!!!
remoteViews.setOnClickPendingIntent(R.id.widget_button, MyWidgetProvider.buildButtonPendingIntent(context));
MyWidgetProvider.pushWidgetUpdate(context.getApplicationContext(), remoteViews);
}
private int getImageToSet() {
clickCount++;
return clickCount % 2 == 0 ? R.drawable.me : R.drawable.wordpress_icon;
}
}
我应该做什么样的修改?我不需要按钮。我只想让图片按月份显示。
自己用 Calendar
解决了。
我有 12 张图像保存在 drawable 中,文件名根据月份命名,即 jan、feb、mar、apr 等。如何根据当前在 Android 小部件的 ImageView 中显示图像月?例如,当前是四月,则应显示文件名为 apr 的图像。 我正在关注 https://looksok.wordpress.com/2012/12/15/android-complete-widget-tutorial-including-source-code/
的教程public class MyWidgetIntentReceiver extends BroadcastReceiver {
private static int clickCount = 0;
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("pl.looksok.intent.action.CHANGE_PICTURE")){
updateWidgetPictureAndButtonListener(context);
}
}
private void updateWidgetPictureAndButtonListener(Context context) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_demo);
remoteViews.setImageViewResource(R.id.widget_image, getImageToSet());
//REMEMBER TO ALWAYS REFRESH YOUR BUTTON CLICK LISTENERS!!!
remoteViews.setOnClickPendingIntent(R.id.widget_button, MyWidgetProvider.buildButtonPendingIntent(context));
MyWidgetProvider.pushWidgetUpdate(context.getApplicationContext(), remoteViews);
}
private int getImageToSet() {
clickCount++;
return clickCount % 2 == 0 ? R.drawable.me : R.drawable.wordpress_icon;
}
} 我应该做什么样的修改?我不需要按钮。我只想让图片按月份显示。
自己用 Calendar
解决了。