Android 显示基于月份的Widget ImageView

Android 显示基于月份的Widget ImageView,android,android-widget,android-imageview,android-appwidget,Android,Android Widget,Android Imageview,Android Appwidget,我有12张图像保存在drawable中,文件名根据月份命名,即1月、2月、3月、4月等。如何根据当前月份在Android widget的ImageView中显示图像?例如,当前是四月,所以应该显示文件名为apr的图像。 我是从以下教程 } 我应该做什么修改?我不需要这个按钮。我只希望图像按月份显示。自己用日历解决。最好使用开关盒或常量数组中的索引 public class MyWidgetIntentReceiver extends BroadcastReceiver { private st

我有12张图像保存在drawable中,文件名根据月份命名,即1月、2月、3月、4月等。如何根据当前月份在Android widget的ImageView中显示图像?例如,当前是四月,所以应该显示文件名为apr的图像。 我是从以下教程

}
我应该做什么修改?我不需要这个按钮。我只希望图像按月份显示。

自己用日历解决。

最好使用开关盒或常量数组中的索引
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;
}