有人可以告诉我如何用两组R.drawable.images海盗创建if-else语句吗?

我已经尝试过,但是收到一个错误代码,提示海盗未解决。

位图图标= BitmapFactory.decodeResource(getResources(),pirates [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" />




主要活动:

     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]);

09-25 18:45