Loading Integer Array from xml

后端 未结 4 552
猫巷女王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:18

    Just make it a normal resource array. You could do it like this:

    
    
       
           @drawable/home
           @drawable/settings
           @drawable/logout
       
    
    

    Then don't make a int[] just make a TypedArray like this:

    TypedArray icons = getResources().obtainTypedArray(R.array.icons);
    

    and get it with:

    imageview.setImageDrawable(mIcons.getDrawable(position));
    

提交回复
热议问题