安卓中注册的分步操作

安卓中注册的分步操作:
1、涉及到四个类:
Regiter2Activity———注册界面(控制分步界面的加载)
BaseActivity————-自定义的activity类(实现了公共方法)
RegisterStep————注册分步界面的模板类
StepPhone ————-注册分步界面的实例化
2、类之间的关系操作:
(1)、每个StepPhone 继承模板类RegisterStep;
(2)、模板类RegisterStep中通过注册界面Regiter2Activity的实例化,可以操作注册界面Regiter2Activity的的UI方法;
实现:在RegisterStep中(定义接口,在注册界面中实例化)

    public void setOnNextActionListener(onNextActionListener listener) {
        mOnNextActionListener = listener;
    }

    public interface onNextActionListener {
        void next();
    }

在中Regiter2Activity:

import com.itau.yamadv.ui.regiter.RegisterStep.onNextActionListener;

public class Regiter2Activity extends BaseActivity implements OnClickListener,onNextActionListener {}

3、执行流程:
(1)、实例化注册分步界面stepphone:

// 设置每页的控件的内容
    private RegisterStep initStep() {
        switch (mCurrentStepIndex) {
        case 1:
            if (mStepPhone == null) {
      //mVfFlipper.getChildAt(0) 获取viewpage中的一个分步界面,并实例化
        mStepPhone = new StepPhone(this, mVfFlipper.getChildAt(0));
            }
//
            yeshu_txt.setText("1/4");
            tvHeadercenter_txt.setText("注册新账号");
            mBtnNext.setText("注册");
            return mStepPhone;
            }

//模板类实例化时执行的初始化:

public RegisterStep(Regiter2Activity activity, View contentRootView) {
        mActivity = activity;
        mContext = (Context) mActivity;
        mContentRootView = contentRootView;
        initViews();
        initEvents();
    }

/viewpage的界面设置:

            <ViewFlipper
                android:id="@+id/reg_vf_viewflipper"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:flipInterval="1000"
                android:persistentDrawingCache="animation" >

                <!-- 1  电话号码 -->

                <include
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    layout="@layout/include_register_phone" />
                <!-- 2  号码验证 -->

                <include
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    layout="@layout/include_register_verify" />

                <!-- 3  用户名和 性别 -->

                <include
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    layout="@layout/include_register_baseinfo" />
                <!-- 3  密码 -->

                <include
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    layout="@layout/include_register_setpwd" />
            </ViewFlipper>

(2)、注册输入电话号码,点击下一步:

private void doNext() {  //操作分步界面中的方法,进行验证界面的信息
        try {  
    if (mCurrentStep.validate()) {
        if (mCurrentStep.isChange()) { // 信息被验证,并且没有错误
                    mCurrentStep.doNext(); // /进入验证
                } else {
                    next(); // 当前步骤已完成,进入下一跳
                }
            }
        } catch (Exception ex) {
        }
    }

(3)、分步界面的信息验证:
mOnNextActionListener.next(); // //连接到主线UI的next()操作

@Override
    public void doNext() {
         handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    responseInfo = (String) msg.obj;
                    System.out.println("####"+responseInfo);
                    if("\"OK\"".equals(responseInfo)){
                        mBackDialog = BaseDialog.getDialog(mActivity, "确认手机号码",
                                "我们将发送验证码短信到这个号码:" + mPhone, "确认",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog,
                                            int which) {
                                        dialog.dismiss();
                                        Data.mapRegister.put("phomeNum", mPhone);
                                        mIsChange = false;
                                        mOnNextActionListener.next(); // //连接到主线UI的next()操作
                                    }
                                }, "取消", new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog,
                                            int which) {
                                        dialog.cancel();
                                    }
                                });
                        mBackDialog
                                .setButton1Background(R.drawable.btn_default_popsubmit);
                        mBackDialog.show();
                    }else{
                        showCustomToast("手机号码不可用或已被注册");
                    }
                }
            };
            getFromServer();
    }

(4)、分步验证成功后,跳转到下页分步(在注册界面中的next方法中实现)

@Override
    public void next() {
        try {
            mCurrentStepIndex++;
            mCurrentStep = initStep(); // RegisterStep 加载下一页的内容
            mCurrentStep.setOnNextActionListener(this); //下一分布界面的方法监听注册
            //注册界面中分布界面的加载
            mVfFlipper.setInAnimation(this, R.anim.push_left_in);
            mVfFlipper.setOutAnimation(this, R.anim.push_left_out);
            mVfFlipper.showNext(); // // 跳转到下一页
        } catch (Exception ex) {
        }
    }

(5)、注册界面返回上一步:

private void doPrevious() {
        try {
            mCurrentStepIndex--;
            mCurrentStep = initStep();
            mCurrentStep.setChange(true);
            mCurrentStep.setOnNextActionListener(this);

            mVfFlipper.setInAnimation(this, R.anim.push_right_in); // 设置viewflipper
                                                                    // 的子布局的跳转动画
            mVfFlipper.setOutAnimation(this, R.anim.push_right_out);
            mVfFlipper.showPrevious();
        } catch (Exception ex) {
        }

    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值