2

hai friends...my java file indicate this error: R.styleable cannot be resolved....

my xml file:

<?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>

source code:

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(); 
    }
kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
RBJ
  • 951
  • 8
  • 22
  • 34
  • possible duplicate of [Android Hello, Gallery tutorial -- "R.styleable cannot be resolved"](http://stackoverflow.com/questions/1717489/android-hello-gallery-tutorial-r-styleable-cannot-be-resolved) – Ian Roberts Nov 20 '12 at 22:26
  • Make sure you explicitly import your R class – Deni Erdyneev Jan 21 '17 at 10:13

3 Answers3

4

create an xml file under values folder, with the name attributes.xml and copy below contents to it.

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

This should work.

Knight
  • 679
  • 5
  • 3
3

According to this forum thread you need to change:

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

to

TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
-4

For me, this did the trick:

import android.R;
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
android_devrah
  • 270
  • 4
  • 11
  • This shouldn't be the accepted answer. REad this answer instead http://stackoverflow.com/questions/6675403/r-styleable-can-not-be-resolved-why – quinestor Nov 20 '12 at 13:20
  • 1
    you can't use android r file , you must use your own created file in gen folder – Ahmed Salem Sep 09 '15 at 08:11