Created
May 15, 2014 20:38
-
-
Save swanson/c6c88710ff63d88de004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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