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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With