Android登陆注册
Posted ``Laity .
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android登陆注册相关的知识,希望对你有一定的参考价值。
目录
主页.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<ImageView
android:layout_marginTop="30dp"
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/imageView"
android:background="#F1F1F1"
/>
<TextView
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="账号名"
/>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="个人信息"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="订单列表"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="修改密码"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="意见反馈"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="退出"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
主页.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import com.example.smartcity.gerenzhongxing.denglu.DengLu;
import com.example.smartcity.gerenzhongxing.gerenxingxi.DingDangLieBiao;
import com.example.smartcity.gerenzhongxing.gerenxingxi.FangKuiXingXi;
import com.example.smartcity.gerenzhongxing.gerenxingxi.GeRenXingXi;
import com.example.smartcity.gerenzhongxing.gerenxingxi.XiuGaiMiMa;
import com.example.smartcity.gerenzhongxing.gerenxingxi.XiuGaiXingXi;
import org.json.JSONException;
import org.json.JSONObject;
public class GeRenZhongXing extends Fragment implements View.OnClickListener
TextView textView1,textView,textView2,textView3,textView4,textView5;
ImageView imageView;
View view;
String token="";
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
view= LayoutInflater.from(getContext()).inflate(R.layout.xinwen,null,false);
SharedPreferences sharedPreferences=getActivity().getSharedPreferences("name",0);
token=sharedPreferences.getString("token","");
textView=view.findViewById(R.id.textView);
textView1=view.findViewById(R.id.textView1);
textView2=view.findViewById(R.id.textView2);
textView3=view.findViewById(R.id.textView3);
textView4=view.findViewById(R.id.textView4);
textView5=view.findViewById(R.id.textView5);
imageView=view.findViewById(R.id.imageView);
textView.setOnClickListener(this);
imageView.setOnClickListener(this);
textView1.setOnClickListener(this);
textView2.setOnClickListener(this);
textView3.setOnClickListener(this);
textView4.setOnClickListener(this);
textView5.setOnClickListener(this);
// 获取数据
huoqushuju();
return view;
private void huoqushuju()
if (!token.equals(""))
new Thread(new Runnable()
@Override
public void run()
try
String data=new GongJuLei().getHuoquGeRenXingXi(token);
JSONObject jsonObject=new JSONObject(data);
JSONObject jsonObject1=jsonObject.getJSONObject("user");
getActivity().runOnUiThread(new Runnable()
@Override
public void run()
try
textView.setText("账号名:"+jsonObject1.getString("userName"));
Glide.with(getContext()).load(url).into(imageView);
catch (JSONException e)
e.printStackTrace();
);
catch (Exception e)
e.printStackTrace();
).start();
@Override
public void onClick(View view)
switch (view.getId())
case R.id.imageView:
if (token.equals(""))
startActivity(new Intent(getContext(), DengLu.class));
break;
case R.id.textView:
if (token.equals(""))
startActivity(new Intent(getContext(), DengLu.class));
break;
case R.id.textView1:
if (token.equals(""))
startActivity(new Intent(getContext(), DengLu.class));
else
startActivity(new Intent(getContext(), GeRenXingXi.class));
break;
case R.id.textView2:
if (token.equals(""))
startActivity(new Intent(getContext(), DengLu.class));
else
startActivity(new Intent(getContext(), DingDangLieBiao.class));
break;
case R.id.textView3:
if (token.equals(""))
startActivity(new Intent(getContext(), DengLu.class));
else
startActivity(new Intent(getContext(), XiuGaiMiMa.class));
break;
case R.id.textView4:
if (token.equals(""))
startActivity(new Intent(getContext(), DengLu.class));
else
startActivity(new Intent(getContext(), FangKuiXingXi.class));
break;
case R.id.textView5:
startActivity(new Intent(getContext(), DengLu.class));
break;
登陆.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".gerenzhongxing.denglu.DengLu"
android:orientation="vertical"
android:gravity="right"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:text="登陆"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:hint="请输入账号"
android:singleLine="true"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:hint="请输入密码"
android:singleLine="true"
android:inputType="textPassword"
/>
<TextView
android:id="@+id/textView"
android:padding="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="注册账号"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="登陆"
/>
</LinearLayout>
</LinearLayout>
登陆.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import com.example.smartcity.daohanglang.DaoHangLang;
import org.json.JSONException;
import org.json.JSONObject;
public class DengLu extends AppCompatActivity
EditText editText1,editText2;
Button button;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deng_lu);
editText1=findViewById(R.id.editText1);
editText2=findViewById(R.id.editText2);
button=findViewById(R.id.button);
textView=findViewById(R.id.textView);
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
startActivity(new Intent(DengLu.this,ZhuChe.class));
);
button.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
if (!editText1.getText().equals("")&&!editText2.getText().equals(""))
// 获取数据
new Thread(new Runnable()
@Override
public void run()
try
String data=new GongJuLei().getDengLu(editText1.getText().toString().trim(),editText2.getText().toString().trim());
JSONObject jsonObject=new JSONObject(data);
runOnUiThread(new Runnable()
@Override
public void run()
try
if (jsonObject.getString("msg").equals("操作成功"))
SharedPreferences sharedPreferences=getSharedPreferences("name",0);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("token",jsonObject.getString("token"));
editor.commit();
startActivity(new Intent(DengLu.this, DaoHangLang.class));
finish();
Toast.makeText(DengLu.this,jsonObject.getString("msg") +"", Toast.LENGTH_SHORT).show();
catch (JSONException e)
e.printStackTrace();
);
catch (Exception e)
e.printStackTrace();
).start();
else
Toast.makeText(DengLu.this, "数据未填写完整", Toast.LENGTH_SHORT).show();
);
注册.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".gerenzhongxing.denglu.DengLu"
android:orientation="vertical"
android:gravity="right"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="注册"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:hint="请输入账号名"
android:singleLine="true"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:hint="请输入手机号"
android:singleLine="true"
android:inputType="textPassword"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:hint="请输入密码"
android:singleLine="true"
android:inputType="textPassword"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText4"
android:hint="请重复密码"
android:singleLine="true"
android:inputType="textPassword"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="注册"
/>
</LinearLayout>
</LinearLayout>
注册.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class ZhuChe extends AppCompatActivity
TextView textView;
Button button;
EditText editText1,editText2,editText3,editText4;
String xinbie="";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zhu_che);
textView=findViewById(R.id.textView);
button=findViewById(R.id.button);
editText1=findViewById(R.id.editText1);
editText2=findViewById(R.id.editText2);
editText3=findViewById(R.id.editText3);
editText4=findViewById(R.id.editText4);
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
finish();
);
button.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
new Thread(new Runnable()
@Override
public void run()
try
String data=new GongJuLei().getZhuChe(editText1.getText().toString(),editText2.getText().toString(),editText3.getText().toString(),xinbie);
JSONObject jsonObject=new JSONObject(data);
runOnUiThread(new Runnable()
@Override
public void run()
try
if (jsonObject.getString("msg").equals("操作成功"))
finish();
Toast.makeText(ZhuChe.this, jsonObject.getString("msg")+"", Toast.LENGTH_SHORT).show();
catch (JSONException e)
e.printStackTrace();
);
catch (Exception e)
e.printStackTrace();
).start();
);
个人信息.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".gerenzhongxing.gerenxingxi.GeRenXingXi">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="个人信息"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<ImageView
android:background="#F5F5F5"
android:layout_marginTop="20dp"
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/imageView"
/>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
<TextView
android:id="@+id/textView1"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="昵称:"
/>
<TextView
android:id="@+id/textView2"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="邮箱号:"
/>
<TextView
android:id="@+id/textView3"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="电话号码:"
/>
<TextView
android:id="@+id/textView4"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="性别:"
/>
<TextView
android:id="@+id/textView5"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="身份证号码:"
/>
<TextView
android:id="@+id/textView6"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="余额:"
/>
<TextView
android:id="@+id/textView7"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="积分:"
/>
<TextView
android:id="@+id/textView8"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="修改"
android:id="@+id/button"
/>
</LinearLayout>
个人信息.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class GeRenXingXi extends AppCompatActivity
TextView textView,textView1,textView2,textView3,textView4,
textView5,textView6,textView7,textView8;
ImageView imageView;
String token="";
Button button;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ge_ren_xing_xi);
token=getSharedPreferences("name",0).getString("token","");
textView=findViewById(R.id.textView);
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
finish();
);
imageView=findViewById(R.id.imageView);
textView1=findViewById(R.id.textView1);
textView2=findViewById(R.id.textView2);
textView3=findViewById(R.id.textView3);
textView4=findViewById(R.id.textView4);
textView5=findViewById(R.id.textView5);
textView6=findViewById(R.id.textView6);
textView7=findViewById(R.id.textView7);
textView8=findViewById(R.id.textView8);
button=findViewById(R.id.button) ;
button.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
startActivity(new Intent(GeRenXingXi.this,XiuGaiXingXi.class));
);
// 获取数据
new Thread(new Runnable()
@Override
public void run()
try
String data=new GongJuLei().getHuoquGeRenXingXi(token);
JSONObject jsonObject=new JSONObject(data);
JSONObject jsonObject1=jsonObject.getJSONObject("user");
runOnUiThread(new Runnable()
@Override
public void run()
try
Glide.with(GeRenXingXi.this).load(url).into(imageView);
textView1.setText(jsonObject1.getString("userName"));
textView2.setText(jsonObject1.getString("nickName"));
textView3.setText(jsonObject1.getString("email"));
textView4.setText(jsonObject1.getString("phonenumber"));
if (jsonObject1.getString("sex").equals("0"))
textView5.setText("男");
else
textView5.setText("女");
StringBuffer stringBuffer=new StringBuffer(jsonObject1.getString("idCard"));
stringBuffer.replace(2,14,"***");
textView6.setText(stringBuffer);
textView7.setText(jsonObject1.getString("balance"));
textView8.setText(jsonObject1.getString("score"));
catch (JSONException e)
e.printStackTrace();
);
catch (Exception e)
e.printStackTrace();
).start();
修改个人信息.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".gerenzhongxing.gerenxingxi.XiuGaiXingXi">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="修改信息"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<EditText
android:id="@+id/editText1"
android:hint="请输入昵称"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/editText2"
android:hint="请输入电话号码"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/editText3"
android:hint="请输入身份证号码"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioGroup
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:id="@+id/radioGroup"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton1"
android:text="男"
/>
<RadioButton
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton2"
android:text="女"
/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="修改"
/>
</LinearLayout>
修改个人信息.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class XiuGaiXingXi extends AppCompatActivity
TextView textView;
Button button;
EditText editText1,editText2,editText3;
RadioGroup radioGroup;
String token="",xinbie="";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xiu_gai_xing_xi);
textView=findViewById(R.id.textView);
button=findViewById(R.id.button);
editText1=findViewById(R.id.editText1);
editText2=findViewById(R.id.editText2);
editText3=findViewById(R.id.editText3);
radioGroup=findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i)
switch (i)
case R.id.radioButton1:
xinbie="0";
break;
case R.id.radioButton2:
xinbie="1";
break;
);
token=getSharedPreferences("name",0).getString("token","");
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
finish();
);
button.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
if (!editText1.getText().toString().trim().equals("")&&
!editText2.getText().toString().trim().equals("")&&
!editText3.getText().toString().trim().equals("")&&
!xinbie.equals("")
)
if (editText2.length()==11)
if (editText3.length()==18)
new Thread(new Runnable()
@Override
public void run()
try
String data=new GongJuLei().getXiuGaiXingXi(token,
editText1.getText().toString().trim(),
editText2.getText().toString().trim(),
editText3.getText().toString().trim(),xinbie);
JSONObject jsonObject=new JSONObject(data);
runOnUiThread(new Runnable()
@Override
public void run()
try
if (jsonObject.getString("msg").equals("操作成功"))
finish();
Toast.makeText(XiuGaiXingXi.this, jsonObject.getString("msg")+"", Toast.LENGTH_SHORT).show();
catch (JSONException e)
e.printStackTrace();
);
catch (Exception e)
e.printStackTrace();
).start();
else
Toast.makeText(XiuGaiXingXi.this, "请输入18位身份证号码", Toast.LENGTH_SHORT).show();
else
Toast.makeText(XiuGaiXingXi.this, "请输入11位电话号码", Toast.LENGTH_SHORT).show();
else
Toast.makeText(XiuGaiXingXi.this, "请输入完整", Toast.LENGTH_SHORT).show();
);
修改密码.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".gerenzhongxing.gerenxingxi.XiuGaiMiMa">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="修改密码"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:hint="请输入旧密码"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:hint="请输入新密码"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:hint="请重复密码"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="修改"
/>
</LinearLayout>
修改密码.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class XiuGaiMiMa extends AppCompatActivity
TextView textView;
EditText editText1,editText2,editText3;
Button button;
String token="";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xiu_gai_mi_ma);
token=getSharedPreferences("name",0).getString("token","");
textView=findViewById(R.id.textView);
editText1=findViewById(R.id.editText1);
editText2=findViewById(R.id.editText2);
editText3=findViewById(R.id.editText3);
button=findViewById(R.id.button);
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
finish();
);
button.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
if (editText2.getText().toString().trim().equals(editText3.getText().toString().trim()))
new Thread(new Runnable()
@Override
public void run()
try
String data=new GongJuLei().getXiuGaiMiMa(token,editText1.getText().toString().trim(),editText2.getText().toString().trim());
JSONObject jsonObject=new JSONObject(data);
runOnUiThread(new Runnable()
@Override
public void run()
try
if (!editText1.getText().toString().trim().equals("")&&!editText2.getText().toString().trim().equals(""))
if (jsonObject.getString("msg").equals("操作成功"))
finish();
Toast.makeText(XiuGaiMiMa.this, jsonObject.getString("msg")+"", Toast.LENGTH_SHORT).show();
else
Toast.makeText(XiuGaiMiMa.this, "未填写完整", Toast.LENGTH_SHORT).show();
catch (JSONException e)
e.printStackTrace();
);
catch (Exception e)
e.printStackTrace();
).start();
else
Toast.makeText(XiuGaiMiMa.this, "新密码不一致", Toast.LENGTH_SHORT).show();
);
意见反馈.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".gerenzhongxing.gerenxingxi.FangKuiXingXi">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="反馈信息"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_margin="20dp"
android:background="#fff"
app:cardCornerRadius="30dp"
app:cardBackgroundColor="#EEEEEE"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:background="@null"
android:id="@+id/editText"
android:hint="请输入反馈信息"
android:gravity="left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:maxLength="150"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="还剩150个字可以输入"
android:id="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="30dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="提交"
/>
</LinearLayout>
意见反馈.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class FangKuiXingXi extends AppCompatActivity
TextView textView,textView1;
EditText editText;
Button button;
String token="";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fang_kui_xing_xi);
token=getSharedPreferences("name",0).getString("token","");
textView=findViewById(R.id.textView);
textView.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
finish();
);
textView1=findViewById(R.id.textView1);
editText=findViewById(R.id.editText);
button=findViewById(R.id.button );
editText.addTextChangedListener(new TextWatcher()
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
@Override
public void afterTextChanged(Editable editable)
textView1.setText("还剩"+(150-editText.length())+"个字可以输入");
if (editText.length()==150)
Toast.makeText(FangKuiXingXi.this, "不可以输入了", Toast.LENGTH_SHORT).show();
);
button.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
if (!editText.getText().toString().trim().equals(""))
new Thread(new Runnable()
@Override
public void run()
try
String data=new GongJuLei().getFangKuiXingXi(token,editText.getText().toString().trim());
JSONObject jsonObject=new JSONObject(data );
runOnUiThread(new Runnable()
@Override
public void run()
try
if (jsonObject.getString("msg").equals("操作成功"))
finish();
Toast.makeText(FangKuiXingXi.this, jsonObject.getString("msg")+"", Toast.LENGTH_SHORT).show();
catch (JSONException e)
e.printStackTrace();
);
catch (Exception e)
e.printStackTrace();
).start();
else
Toast.makeText(FangKuiXingXi.this, "未填写", Toast.LENGTH_SHORT).show();
);
订单列表.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".gerenzhongxing.gerenxingxi.DingDangLieBiao">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="订单列表"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Te以上是关于Android登陆注册的主要内容,如果未能解决你的问题,请参考以下文章
俺是菜鸟,俺想做一个俺android的登陆注册功能,利用socket通信,数据库是mysql。
android asmack 注册 登陆 聊天 多人聊天室 文件传输