2010-11-26 74 views
2

海的朋友......我的Java文件指出這個錯誤: R.styleable解決不了....R.styleable解決不了

我的XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/videoGrdVw" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:numColumns="auto_fit" 
    android:verticalSpacing="5dip" 
    android:horizontalSpacing="5dip" 
    android:columnWidth="80dip" 
    android:stretchMode="columnWidth" 
    android:gravity="center"/> 

<ImageSwitcher 

    android:id="@+id/switcher" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"> 

    </ImageSwitcher> 
    <resources> 
    <declare-styleable name="HelloGallery"> 
    <attr name="android:galleryItemBackground" /> 
    </declare-styleable> 
    </resources> 


    </LinearLayout> 

源代碼如下:

private class VideoGalleryAdapter extends BaseAdapter 
{ 
    private int itemBackground; 

    public VideoGalleryAdapter(Context c) 
    { 
     _context = c; 
     TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); 
     itemBackground = a.getResourceId(
       R.styleable.Gallery1_android_galleryItemBackground, 0); 
     a.recycle(); 
    } 
+0

可能的重複[Android Hello,Gallery tutorial - 「R.styleable can not be resolved」](http://stackoverflow.com/questions/1717489/android-hello-gallery-tutorial-r-styleable-cannot-解決) – 2012-11-20 22:26:43

+0

請確保您明確導入您的R類 – 2017-01-21 10:13:39

回答

-2

對於我來說,這並獲得成功:

import android.R; 
3

根據這一forum thread您需要更改:

TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); 

TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1); 
+0

我正在改變編碼....同樣的問題.....你有任何其他的想法... – RBJ 2010-11-26 09:06:27

+0

閱讀完整的線程,看看是否有其他想法建議。另外,不要接受答案,除非它真的解決了你的問題。這會混淆未來的讀者。 – kgiannakakis 2010-11-26 09:09:17

3

values文件夾下創建一個XML文件,名爲attributes.xml及以下內容複製到它。

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="Gallery1"> 
     <attr name="android:galleryItemBackground"/> 
    </declare-styleable> 
</resources> 

這應該起作用。