I am trying to implement a custom view, for which I want to be able to pass parameters via an XML layout file. The catch is these parameters will be more or less arbitrary; they will eventually be used as parameters to construct a URL (it’s not worthwhile to build and maintain a complete list of valid params).
As such, the method in ApiDemos sample code is not necessarily appropriate, given I do not know the names of the parameters.
What I have attempted to do is the following:
public Chart(Context context, AttributeSet attributes) {
super(context, attributes);
params = new HashMap<String, String>();
for(int i = 0; i < attributes.getAttributeCount(); i++)
params.put(attributes.getAttributeName(i), attributes.getAttributeValue(i));
}
This may not be the best way to go about this.. but the main issue I have is how do I filter out android: attributes (ie. I don’t want android:layout_height, etc. to be in params)?
Found a way to do this by using an overloaded version of getAttributeValue(). Still open for input if there is a better way to do this.