Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styleable cannot be resolved

Here is the code I am using:

public ASSwitch(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray sharedTypedArray = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.ASSwitch,
            0, 0);

       try {
           onText = sharedTypedArray.getText(R.styleable.ASSwtich_onText, null);

       } finally {
           sharedTypedArray.recycle();
       }
}

Here is the attrs.xml file (added to values folder):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="ASSwitch">
        <attr name="onText" format="string" />
        <attr name="offText" format="string" />
        <attr name="onState" format="boolean" />
        <attr name="toogleDrawable" format="string" />
        <attr name="frameDrawable" format="string" />
    </declare-styleable>
</resources>

The answers in these questions couldn't fix the problem. Please don't consider my question as duplicate.

  • Android Hello, Gallery tutorial -- "R.styleable cannot be resolved"

  • Android: How to Declare Styleable in R.java?

  • R.styleable can not be resolved, why?

  • R.styleable cannot be resolved


Update: It seems that I was importing the wrong R class. It shall be the application's R class not android.R.

like image 537
Abdalrahman Shatou Avatar asked Jun 21 '13 19:06

Abdalrahman Shatou


2 Answers

Check your imports:

  • Wrong: Android.R
  • Correct: com.example.yourproject.R

I had the same error when made this customized view. Maybe when follow the guiding step, the helper tool automatically inserts this wrong import.

like image 147
Tin Luu Avatar answered Sep 18 '22 22:09

Tin Luu


It seems that I was importing the wrong R class. It shall be the application's R class not android.R

like image 24
Abdalrahman Shatou Avatar answered Sep 20 '22 22:09

Abdalrahman Shatou