Loading Integer Array from xml

后端 未结 4 532
猫巷女王i
猫巷女王i 2020-12-21 03:57

I have an integer array in an xml file as follows


    @drawable/pic1
    @drawabl         


        
4条回答
  •  有刺的猬
    2020-12-21 04:35

    You need to get an array with id's of your images. Probably this article helps you. And so the code you probably need:

    int[] picArray = new int[4];
    
    for (int i = 1; i <=4; i++)
    {
      try 
      {
        Class res = R.drawable.class;
        Field field = res.getField("pic"+i);
        picArray[i-1] = field.getInt(null);
      }
      catch (Exception e)
      {
        Log.e("MyTag", "Failure to get drawable id.", e);
      }
    }
    

提交回复
热议问题