我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

Android中怎么利用系统对话框实现登陆注册功能

这期内容当中小编将会给大家带来有关Android中怎么利用系统对话框实现登陆注册功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

公司主营业务:成都网站制作、成都网站设计、外贸营销网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联公司推出宣州免费做网站回馈大家。

界面布局xml文件

                            

2.2 后台业务逻辑

/*       * 创建用户登陆的对话框       * 登陆界面包含两个按钮       * 1按钮为登陆       * 2按钮为不登陆试玩       * */      private void CreateLoginAlert()      {          AlertDialog.Builder ad =new AlertDialog.Builder(this);          ad.setTitle("账号登陆");          ad.setView(ViewUtility.GetView(this,R.layout.sub_logindialog));          adadi=  ad.create();          /*               */          adi.setButton("登陆", new OnClickListener(){               @Override              public void onClick(DialogInterface arg0, int arg1) {                                EditText password=    (EditText)adi.findViewById(R.id.txt_password);                  EditText account =(EditText)adi.findViewById(R.id.txt_username);                                    PassWord=password.getText().toString();                  Account=account.getText().toString();                  //生成登陆对话框                  m_Dialog=ProgressDialog.show(Main.this, "请等待...", "正在为你登陆...",true);                   mRedrawHandler.sleep(100);                      }          });                 adi.setButton2("试  玩", new OnClickListener(){              @Override              public void onClick(DialogInterface arg0, int arg1) {                  ViewUtility.NavigateActivate(Main.this, SelectTheme.class);              }          });                  adi.show();                 //设置注册点击事件          TextView  register=(TextView)adi.findViewById(R.id.txt_toregister);          register.setOnClickListener(new  TextView.OnClickListener()          {             public void onClick(View v){                 //创建注册对话框               CreateRegisterAlert();                 adi.dismiss();                              }         });           }         /*       *定时线程做验证用       * */      private RefreshHandler mRedrawHandler = new RefreshHandler();            class RefreshHandler extends Handler {           @Override          public void handleMessage(Message msg) {                              try{                                     //调用网络接口,实现登陆指令                 Boolean flags=    UserDataServiceHelper.Login(Account, PassWord);                     if(flags)                    {                  //保存登陆信息                  UserDataWriteHelper uw=new UserDataWriteHelper(Main.this);                  uw.SaveUserInfoInDB("xuwenbing", Account);                  //提示登陆成功                   Toast.makeText(Main.this, "登陆成功", Toast.LENGTH_SHORT).show();                           //转到主题页面                     ViewUtility.NavigateActivate(Main.this, SelectTheme.class);                 }else                 {                  //失败 显示错误信息                   Toast.makeText(Main.this, "登陆失败", Toast.LENGTH_SHORT).show();                   adi.show();                   adi.findViewById(R.id.txt_loginerror).setVisibility(View.VISIBLE);                  }              }              catch(Exception e)              {                  e.printStackTrace();                                          }              finally{                  m_Dialog.dismiss();                      }          }          public void sleep(long delayMillis) {              this.removeMessages(0);              sendMessageDelayed(obtainMessage(0), delayMillis);          }      };

 3 注册对话框的实现
 3.1  对话框界面布局xml文件

                                                                                                                       

3.2  后台业务逻辑

/*创建注册对话框*/      private void CreateRegisterAlert()      {          //registerdialog          AlertDialog.Builder ad =new AlertDialog.Builder(this);          ad.setTitle("注册账号");          ad.setView(ViewUtility.GetView(this,R.layout.sub_registerdialog));          registerdialog=  ad.create();                  registerdialog.setButton("注册", new OnClickListener(){              @Override              public void onClick(DialogInterface arg0, int arg1) {                            EditText password=    (EditText)registerdialog.findViewById(R.id.txt_password);                  EditText account =(EditText)registerdialog.findViewById(R.id.txt_username);                  EditText nicename =(EditText)registerdialog.findViewById(R.id.txt_nicename);                                 PassWord=password.getText().toString();                  Account=account.getText().toString();                  NiceName=nicename.getText().toString();                  //生成注册对话框                  m_Dialog=ProgressDialog.show(Main.this, "请等待...", "正在为你注册...",true);                  mRegsiterHandler.sleep(100);                      }          });                  registerdialog.setButton2("试  玩", new OnClickListener(){              @Override              public void onClick(DialogInterface arg0, int arg1) {                  ViewUtility.NavigateActivate(Main.this, SelectTheme.class);              }          });                  registerdialog.show();            }      /*       *定时注册程序       * */      private RegsiterHandler mRegsiterHandler = new RegsiterHandler();            class RegsiterHandler extends Handler {           @Override          public void handleMessage(Message msg) {                              try{                                     //调用网络接口,实现注册指令                 Boolean flags=    UserDataServiceHelper.Register(Account, PassWord,NiceName);                     if(flags)                    {                  //保存注册信息                  UserDataWriteHelper uw=new UserDataWriteHelper(Main.this);                  uw.SaveUserInfoInDB("xuwenbing", Account);                  //提示注册成功                   Toast.makeText(Main.this, "注册成功", Toast.LENGTH_SHORT).show();                           //转到主题页面                     ViewUtility.NavigateActivate(Main.this, SelectTheme.class);                 }else                 {                  //失败 显示错误信息                   Toast.makeText(Main.this, "注册失败", Toast.LENGTH_SHORT).show();                   registerdialog.show();                   registerdialog.findViewById(R.id.txt_loginerror).setVisibility(View.VISIBLE);                  }              }              catch(Exception e)              {                  e.printStackTrace();                                          }              finally{                  m_Dialog.dismiss();                      }          }          public void sleep(long delayMillis) {              this.removeMessages(0);              sendMessageDelayed(obtainMessage(0), delayMillis);          }      };

上述就是小编为大家分享的Android中怎么利用系统对话框实现登陆注册功能了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。


网页名称:Android中怎么利用系统对话框实现登陆注册功能
链接URL:http://mswzjz.cn/article/ijsjec.html

其他资讯