Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've created a combo box control with a edittext and spinner. I'm trying to let the android:prompt attribute be passed onto the spinner, which means I need to catch it in the constructor which passes my the AttributeSet and set it on the spinner. I can't figure out how to get the value of the prompt. I'm trying,

int[] ra = { android.R.attr.prompt };
TypedArray ta = context.getTheme().obtainStyledAttributes(ra); 
int id = ta.getResourceId(0, 0); 

I get back 0, which means it didn't find the attribute. I also did a ta.count() which returned 0. So I'm not getting anything back.

My XML simply defines an android:prompt value.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
777 views
Welcome To Ask or Share your Answers For Others

1 Answer

I just wrote an answer explaining the whole process for using XML with custom UI elements. In your case, there is no need to declare a styleable, as you don't need custom attributes. Using android.R.attr.prompt as the int id will work fine. R.styleable.className_attributeName will only work if you defined your attributes in the styleable and you retrieved them by passing R.styleable.className into obtainStyledAttributes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...