Created
March 4, 2013 05:39
-
-
Save noxi515/5080193 to your computer and use it in GitHub Desktop.
AppWidgetでarrayからDrawableリソースをセットするサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<!-- ドロイド君画像 --> | |
<array name="droid_images"> | |
<item>@drawable/ic_droid_default</item> | |
<item>@drawable/ic_droid_cupcake</item> | |
<item>@drawable/ic_droid_honeycomb</item> | |
<item>@drawable/ic_droid_ics</item> | |
<item>@drawable/ic_droid_00</item> | |
<item>@drawable/ic_droid_01</item> | |
<item>@drawable/ic_droid_02</item> | |
<item>@drawable/ic_droid_03</item> | |
</array> | |
</resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.co.noxi.weathernow.appwidget.views; | |
import android.content.Context; | |
import android.content.res.TypedArray; | |
import android.widget.RemoteViews; | |
import java.util.Calendar; | |
import java.util.Random; | |
import jp.co.noxi.weathernow.R; | |
import jp.co.noxi.weathernow.appwidget.AppWidgetData; | |
/** | |
* 吹き出しウィジェットで表示するRemoteViews作成クラス | |
*/ | |
public abstract class PopupWidgetView extends WidgetViewBase { | |
@Override | |
public void prepareView(Calendar baseCalendar) { | |
// Set droid image | |
final TypedArray a = mContext.getResources().obtainTypedArray(R.array.droid_images); | |
mRootViews.setImageViewResource(R.id.droid, a.getResourceId( | |
new Random().nextInt(a.length()), R.drawable.ic_droid_00)); | |
a.recycle(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment