In case you don't know what would go in these classes then please look here! Also, I am not 100% sure this would work yet, I am testing this out
I am currently working on creating a simplified base class that would simplify using custom xml attributes in class AttributeSet
's
basically, this is what I am kind of look for as a final result...
public class SimpleViewImplementation extends SimpleView<LinearLayout> {
// List of members here
private String value;
public SimpleViewImplementation(Context context) {
super(context);
}
public SimpleViewImplementation(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void setFromStyledAttributes(TypedArray attr) {
// Set conditions for each member here via TypedArray (use setters)
setValue(attr.getString(R.styleable.SimpleViewImplementation_value));
}
@Override
protected void initView() {
// Set initial conditions for each member here
this.value = "this is the default value!";
}
// Getters & Setters here for members
public String getValue() { return this.value; }
public void setValue(String value) {
this.value = value;
this.updateViewOnSet();
}
}
and this is the "base" class that does all the magic. The problem is really the class "signature". I need it to extend type T
. Either I missed how to do that in my research online, or it cannot be done. If it cannot be done, then are they any suggestions to get somewhat of my results above. In case you don't know what would go in these classes then please look here!
public abstract class SimpleView<T> { // I would like this class to extend Type T. ie SimpleView<LinearLayout> would extend this class to be a LinearLayout...getting rid of compile-time errors below
// ^ can I put anything here????
public SimpleView(Context context) {
super(context); // CTE (Compile-time error)
initView();
}
public SimpleView(Context context, AttributeSet attrs) {
super(context, attrs); // CTE
initView();
TypedArray attr = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DrawerSongDetail, 0, 0);
try {
this.setFromStyledAttributes(attr);
} finally {
attr.recycle();
}
}
// Sets all members based on AttributeSet parameter
abstract protected void setFromStyledAttributes(TypedArray attr);
// Sets all initial values of members
abstract protected void initView();
private void updateViewOnSet() {
this.requestLayout(); // CTE
this.invalidate(); // CTE
}
}