Android Hello, Gallery tutorial — “R.styleable cannot be resolved”

前端 未结 7 1904
一整个雨季
一整个雨季 2020-11-27 13:23

When working on the Hello, Gallery tutorial/sample app, after following the instructions on the site, Eclipse reported that R.styleable cannot be resolved.

What is t

7条回答
  •  独厮守ぢ
    2020-11-27 14:14

    Per this thread, R.styleable has been removed from android 1.5 and higher.

    There are a number of ways to get the sample to work, the simplest that I found was recommended by Justin Anderson in the thread linked to above:

    1. Create a new XML file called "resources.xml" with the following content:

       
       
           
               
           
      
      
    2. Place the XML file in the res\values directory (alongside strings.xml)

    3. Update the constructor for your ImageAdapter with the following (assuming the ImageAdapter class is defined in its own file):

      public ImageAdapter(Context c) {
          mContext = c;
          TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
          mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
          a.recycle();
      }
      

    This solution basically defines the styleable attribute as a resource of the app itself and gives it the necessary structure to work in the app. Note that the app can run fine if you just omit the two lines of code (prior to a.recycle();), all this code does is set a grey background around the images in the Gallery.

提交回复
热议问题