源码地址:http://git.oschina.net/zj2012zy/Android-Demo/tree/master/AndroidDemo/setpregister
效果如下:
基本思路:
1、定义一个抽象类:
RegisterStep
1 public abstract class RegisterStep { 2 public interface OnNextActionListener { 3 void next(); 4 5 void submit(); 6 } 7 8 protected Activity mActivity; 9 protected Context mContext; 10 11 private View mContentView; 12 13 protected OnNextActionListener mOnNextActionListener; 14 15 public RegisterStep(Activity activity, View contentView) { 16 mActivity = activity; 17 mContext = (Context) mActivity; 18 mContentView = contentView; 19 20 initViews(); 21 initEvents(); 22 } 23 24 public abstract void initViews(); 25 26 public abstract void initEvents(); 27 28 public abstract boolean validate(); 29 30 public View findViewById(int id) { 31 return mContentView.findViewById(id); 32 } 33 34 public void doPrevious() { 35 36 } 37 38 public void doNext() { 39 mOnNextActionListener.submit(); 40 } 41 42 public void nextAnimation() { 43 44 } 45 46 public void preAnimation() { 47 48 } 49 50 public void setOnNextActionListener(OnNextActionListener onNextActionListener) { 51 mOnNextActionListener = onNextActionListener; 52 } 53 }
其中接口OnNextActionListener 中的submit函数用来执行设置好的数据提交。
其中的validate,用来检测每一步的设置值是否合法。
2、定义一系列的具体设置的子类,StepOne,StepTwo....
详情参见源码。