Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the registration function of login interface in Android

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

今天小编给大家分享一下Android如何实现登录界面的注册功能的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

注册一个登录界面在控制台将输入的信息文本选框展示出来

xml界面设计(前面已发)

注册功能实现

package com.example.registerlogin; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;import android.text.TextUtils;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.EditText;import android.widget.RadioGroup;import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener{private EditText mz,zh,mm;private Button btn1;private String name,id,pwd,sex,hobby;private RadioGroup xb;private CheckBox cg,tw,ds; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1=findViewById(R.id.btn1); mz=findViewById(R.id.mz); zh=findViewById(R.id.mz); mm=findViewById(R.id.mz); cg=findViewById(R.id.cg); tw=findViewById(R.id.tw); ds=findViewById(R.id.ds); xb=findViewById(R.id.xb); btn1.setOnClickListener(MainActivity.this); xb.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { {switch (checkedId){ case R.id.nan: sex = "男"; break; case R.id.nu: sex="女"; break; } } } }); } private void getData(){ name=mz.getText().toString().trim(); id=zh.getText().toString().trim(); pwd=mm.getText().toString().trim(); } public void onClick(View v) { switch (v.getId()) { case R.id.btn1: getData(); if (TextUtils.isEmpty(name)) { Toast.makeText(MainActivity.this, "请输入名字", Toast.LENGTH_SHORT).show(); } else if (TextUtils.isEmpty(id)) { Toast.makeText(MainActivity.this, "请输入账号", Toast.LENGTH_SHORT).show(); } else if (TextUtils.isEmpty(pwd)) { Toast.makeText(MainActivity.this, "请输入密码", Toast.LENGTH_SHORT).show(); } else if (TextUtils.isEmpty(sex)) { Toast.makeText(MainActivity.this, "请输入性别", Toast.LENGTH_SHORT).show(); }else if (TextUtils.isEmpty(hobby)) { Toast.makeText(MainActivity.this, "请输入爱好", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(MainActivity.this, "注册成功", Log.i("MainActivity", "检测到你的注册信息:" + "名字:" + name + " 邮箱:" + id + " 性别:" + sex+" 爱好:"+hobby)); } break; } } public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){ String motion =buttonView.getText().toString(); if(isChecked){ if(!hobby.contains(motion)){ hobby = hobby + motion; } }else { if(hobby.contains(motion)){ hobby=hobby.replace(motion,""); } }} }

我没有输入爱好,所以控制台输出null

以上就是"Android如何实现登录界面的注册功能"这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注行业资讯频道。

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report