package com.example.test.bwl;
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.CheckBox;
import android.widget.EditText;
public class LoginActivity extends AppCompatActivity {
EditText edit_inputname,edit_inputpwd;
CheckBox check_reme;
Button btn_login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
initView();
btnloginonClick();
dispalyinfo();
}
private void initView() {
edit_inputname=(EditText) findViewById(R.id.editText_inputname);
edit_inputpwd=(EditText) findViewById(R.id.editText_inputpwd);
check_reme=(CheckBox) findViewById(R.id.checkBox_reme);
btn_login=(Button) findViewById(R.id.button_login);
}
private void btnloginonClick() {
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences.Editor editor=getSharedPreferences("myinfo",0).edit();
editor.putString("name",edit_inputname.getText().toString());
editor.putString("pwd",edit_inputpwd.getText().toString());
editor.putBoolean("st",check_reme.isChecked());
editor.commit();
Intent intent=new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
});
}
private void dispalyinfo() {
String strname = getSharedPreferences("myinfo",0).getString("name","");
String strpwd = getSharedPreferences("myinfo",0).getString("pwd","");
Boolean status = getSharedPreferences("myinfo",0).getBoolean("name",false);
if(status==true){
edit_inputname.setText(strname);
edit_inputpwd.setText(strpwd);
check_reme.setChecked(true);
}else {
edit_inputname.setText("");
edit_inputpwd.setText("");
check_reme.setChecked(false);
}
}
}
哎!~!~!~ 程序崩溃都不知道看log日志的么