今天我完成了忘记密码的activity的设计。
代码为:
package com.example.hotel.Activity; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import com.example.hotel.Database.MysqlUser; import com.example.hotel.R; import java.sql.SQLException; public class NopwdActivity extends AppCompatActivity { private Button Button; private EditText Userid,Userphone; private TextView Pwd; private String searpwd,searphone; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nopwd); Userid=(EditText) findViewById(R.id.userid); Userphone=(EditText)findViewById(R.id.userphone); Pwd=(TextView) findViewById(R.id.pwdresult); Button=findViewById(R.id.searchpwd); Button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Thread thread=new Thread(new Runnable() { @Override public void run() { MysqlUser mysqlUser=new MysqlUser(); try { String sql="select password from userinfo where id='"+Userid.getText().toString()+"'"; searpwd=mysqlUser.select(sql).toString(); String sql2="select phone from userinfo where id='"+Userid.getText().toString()+"'"; searphone=mysqlUser.select(sql2).toString(); } catch (SQLException e) { e.printStackTrace(); } } }); thread.start(); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } search(); } }); } public void search(){ String userid=Userid.getText().toString(); String userphone=Userphone.getText().toString(); if(userphone.equals(searphone)){ Pwd.setText("您的密码为:"+searpwd); } } }