Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve the error "com.android.internal.R cannot be resolved" when I using the android file 'MultiAutoCompleteTextView.java',

Tags:

android

I want to implement my own Tokenizer base on the file "MultiAutoCompleteTextView.java",

but I encounter an error "com.android.internal.R cannot be resolved" when I try to

import "MultiAutoCompleteTextView.java" to my project.

code:

public class MultiAutoCompleteTextView extends AutoCompleteTextView {
    private Tokenizer mTokenizer;

    public MultiAutoCompleteTextView(Context context) {
        this(context, null);
    }

    public MultiAutoCompleteTextView(Context context, AttributeSet attrs) {
        this(context, attrs, com.android.internal.R.attr.autoCompleteTextViewStyle);
    }

    public MultiAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle)     {
        super(context, attrs, defStyle);
    }
    .
    .
    .
}

I haven't research any solutions to resolve this problem.How to correct "com.android.internal.R.attr.autoCompleteTextViewStyle" my own attr?

Thank you for any suggestions.

like image 892
huaigu Avatar asked Aug 15 '10 09:08

huaigu


2 Answers

You could use

    public MultiAutoCompleteTextView(Context context, AttributeSet attrs) {
      this(context, attrs,
        Resources.getSystem().getIdentifier("autoCompleteTextViewStyle", "attr", "android");
    }

You cannot access id's of com.android.internal.R at compile time, but you can access the defined internal resources at runtime and get the resource by name. You should be aware that this is slower than direct access and there is no guarantee, that an internal resource will be available in future versions of android or in vendor-specific builds.

like image 177
yonojoy Avatar answered Nov 12 '22 09:11

yonojoy


Try copying the attr entry from attrs.xml:

<attr name="autoCompleteTextViewStyle" format="reference" />

Add a res/values/attrs.xml to your application and put this line in there. Finally, update your code to reference R from your package:

import com.your.package.R;
...
public MultiAutoCompleteTextView(Context context, AttributeSet attrs) {
    this(context, attrs, R.attr.autoCompleteTextViewStyle);
}

Credit to inazaruk for this procedure.

like image 3
John Mellor Avatar answered Nov 12 '22 09:11

John Mellor