今天对前几天的的界面做了优化
package com.example.math; /* * 注册界面*/ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.view.View; import android.view.WindowManager; import android.widget.EditText; import android.widget.Toast; import com.example.math.bean.User; import com.example.math.repositiory.user_res; import java.util.List; public class register_Activity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); taskbar(); } private void taskbar() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } } public void register(View view) { EditText name = findViewById(R.id.res_name); EditText password = findViewById(R.id.res_password); String a1 = name.getText().toString().trim(); String a2 = password.getText().toString().trim(); new Thread() { @Override public void run() { boolean flag = false; user_res userRes = new user_res(); try { List<User> list = userRes.getAll(); for (int i = 0; i < list.size(); i++) { User user_list = list.get(i); if (a1.equals(user_list.getName())) { flag = true; break; } } } catch (Exception e) { throw new RuntimeException(e); } int msg = 0; if (flag) { msg = 1; } hand1.sendEmptyMessage(msg); } }.start(); } final Handler hand1 = new Handler(Looper.myLooper()) { @Override public void handleMessage(@NonNull Message msg) { if (msg.what == 0) { EditText name = findViewById(R.id.res_name); EditText password = findViewById(R.id.res_password); String a1 = name.getText().toString().trim(); String a2 = password.getText().toString().trim(); add1(a1, a2); startActivity(new Intent(getApplicationContext(), MainActivity.class)); Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "手机号已存在", Toast.LENGTH_LONG).show(); } } }; private void add1(String a1, String a2) { new Thread() { user_res userRes = new user_res(); @Override public void run() { try { userRes.add(a1, a2); } catch (Exception e) { throw new RuntimeException(e); } } }.start(); } }
标签:07,04,res,void,new,user,2023,import,android From: https://www.cnblogs.com/JJTyyds/p/17297541.html