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

前端 未结 7 1902
一整个雨季
一整个雨季 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:18

    I tried everything, but with no luck. The generated R.java was showing the stylable class but the compilation was showing "Stylable Not found". I just added the package name before R, after the change, everything is working fine now...

    So, if your package name is com.example.test, then modify following code...

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

    }

    TO

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

提交回复
热议问题