gpt4 book ai didi

android - If - Else on Pirates 未解决

转载 作者:行者123 更新时间:2023-11-30 03:00:16 26 4
gpt4 key购买 nike

你能告诉我如何用两组 R.drawable.images 盗版创建 if - else 语句吗?

我已经尝试过,但我收到一个错误代码,提示 pirates is un-resolved。

Bitmap icon = BitmapFactory.decodeResource(getResources(),海盗[i]);

这是我在首选项中的内容:

xmlns:android="http://schemas.android.com/apk/res/android"
android:key="wallpaper_settings"
android:title="@string/wallpaper_settings" > <!--must be the same callout from
values->strings-->

<ListPreference
android:key="speed"
android:title="@string/speed_title"
android:entries="@array/timelist"
android:entryValues="@array/actualtime"
android:summary="@string/speed_summary" >
</ListPreference>

<CheckBoxPreference
android:key="checkbox"
android:title="Nature Pictures"
android:summary="For Nature Pictures Option"
android:defaultValue="false" />

主要 Activity :

     public class main_activity extends WallpaperService {

public static final String SHARED_PREFS_NAME="settings_menu";


@Override
public void onCreate() {
super.onCreate();
}

@Override
public void onDestroy() {
super.onDestroy();
}

@Override
public Engine onCreateEngine() {
return new wallpaperEngine();
}

class wallpaperEngine extends Engine implements SharedPreferences.OnSharedPreferenceChangeListener{


private final Handler mhandler = new Handler();


//defines variables


private final Runnable drawrunnable = new Runnable()
{
public void run() {
drawFrame();
}
};
private int i = 0;
private boolean mVisible;
private SharedPreferences mPrefs;
private boolean mcheckbox = false;
public int mSpeed = 10;

int[] pirates = {
R.drawable.image_1,
R.drawable.image_2,
R.drawable.image_3,
R.drawable.image_4

};

//For Nature Pictures
int[] pirates = {
R.drawable.image_a1,
R.drawable.image_a2,
R.drawable.image_a3,
R.drawable.image_a4

};

.......
......

Bitmap icon = BitmapFactory.decodeResource(getResources(),pirates[i]);

i++;

if (i == 14) {
i = 0;

非常感谢

最佳答案

似乎您正在尝试创建两个 int 数组,保存不同的图像集。但是您使用的是相同的变量名 pirates。我建议您定义两个不同的变量 int[] piratesint[] piratesNatural,然后在需要时在这两个数组之间切换。

Bitmap icon; 
if(natural)
icon = BitmapFactory.decodeResource(getResources(),piratesNatural[i]);
else
icon = BitmapFactory.decodeResource(getResources(),pirates[i]);

关于android - If - Else on Pirates 未解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22643685/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com