Skip to content

Instantly share code, notes, and snippets.

@swanson
Created May 15, 2014 20:38
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save swanson/c6c88710ff63d88de004 to your computer and use it in GitHub Desktop.
Save swanson/c6c88710ff63d88de004 to your computer and use it in GitHub Desktop.
/**
* A base class that provides a consistent interface for FormModel-like objects
*/
public abstract class BaseFormModel extends LinearLayout implements FormModel {
protected Context mContext;
public BaseFormModel(Context context) {
super(context);
setup(context);
}
public BaseFormModel(Context context, AttributeSet attrs) {
super(context, attrs);
setup(context);
}
private void setup(Context context) {
mContext = context;
LayoutInflater.from(context).inflate(getLayoutId(), this, true);
}
@Override
public boolean validate() {
return true;
}
/**
* The layout resouce Id to be inflated
*/
protected abstract int getLayoutId();
protected String getString(int resourceId) {
return getContext().getString(resourceId);
}
}
public interface FormModel {
public boolean validate();
public void persist(Bundle outState);
public void restore(Bundle bundle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment