Ok, a quick hack has come back to haunt me, and I now have to find some way
of fixing it.
FYI - This is in aOS 2.2+
Essentially I need to be able to pass some sort of switch value to a View
when I inflate it.
I'll describe what I want to do, and I'll try and show what I'm doing so
that maybe someone will have an idea that might help.
Using a standard inflate call like this:
LayoutInflater inflater =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(resourceId, null);
I want to be able to pass an integer value to the view so I can use it in
the constructor.
In fact, what I really care about is which resource (id) the view was loaded
from.
Now for the actually reason for this, in case there is a better way:
This is some sanitized code that shows what I'm trying to do. There is a
very good chance that I don't have a good grasp of the styles (because i
don't).
public XyzView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
int styleResource = R.style.BasicViewStyle;
if (isFunkyResourceId) {
styleResource = R.style.FunkyViewStyle;
}
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.BasicViewStyle, defStyle, styleResource);
int n = a.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = a.getIndex(i);
switch (attr) {
case R.styleable.BasicViewStyle_mybackground:
mMyBackground = a.getDrawable(attr);
break;
case R.styleable.BasicViewStyle_mydistance:
mMyDistance = a.getDimensionPixelOffset(attr, 0);
break;
...
}
}
...
}
The important part is were I set the styleResource that the values are going
to be loaded from. I need to change them based upon which resource I loaded.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en