is there any way to create a view from inside a library?
i mean buttons or edittext for example.
many tanks in advance
i mean buttons or edittext for example.
many tanks in advance
@ActivityObject
@ShortName("SeekBar")
@DontInheritEvents
@Events(values={"ValueChanged (Value As Int, UserChanged As Boolean)"})
public class SeekBarWrapper extends ViewWrapper<SeekBar>{
@Override
@Hide
public void innerInitialize(final BA ba, final String eventName, boolean keepOldObject) {
if (!keepOldObject)
setObject(new SeekBar(ba.context));
super.innerInitialize(ba, eventName, true);
if (ba.subExists(eventName + "_valuechanged")) {
getObject().setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
ba.raiseEvent(getObject(), eventName + "_valuechanged", progress, fromUser);
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
});
}
}
/**
* Gets or sets the maximum allowed value.
*/
public int getMax() {
return getObject().getMax();
}
public void setMax(int value) {
getObject().setMax(value);
}
/**
* Gets or sets the current value.
*/
public int getValue() {
return getObject().getProgress();
}
public void setValue(int value) {
getObject().setProgress(value);
}
Note that if you inherit from ViewWrapper then you cannot have any instance fields (private or public).
public class MapViewWrapper extends ViewWrapper<MapView> {
// no instance fields allowed
}
public class OSMDroidMapView extends MapViewWrapper{
// can i have instance fields in this class?
private int myValue;
}
This is why using the Tag property to maintain object data is recommended as it is a property of the underlying object and not the wrapper.
class InstanceValues{
int anInt=9;
String myText="Hello world";
}
((MapView)getObject()).setTag(new InstanceValues());
InstanceValues myValues=(InstanceValues) ((MapView)getObject()).getTag();
@Hide
@Override
public Object getTag() {
return super.getTag();
}
@Hide
@Override
public void setTag(Object tag) {
super.setTag(tag);
}