0

我有12個圖像保存在可繪製的文件名按月命名,即1月,2月,3月,4月等。我怎樣才能顯示圖像在基於當前Android小部件ImageView月?例如,當前是4月,因此應顯示帶有文件名稱apr的圖像。 我下面從https://looksok.wordpress.com/2012/12/15/android-complete-widget-tutorial-including-source-code/顯示微件ImageView基於月

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; 
} 

} 教程中,我應該做哪些修改?我不需要按鈕。我只希望根據月份顯示圖像。

回答

0

使用Calendar自己解決。

+0

更好的做法是在const數組中使用switch-case或索引 – Mugen 2015-04-17 13:35:33