sp记住账户名

package com.example.lenovo.lianxiyong;

import android.content.SharedPreferences;
import android.support.v7.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;

public class JizhuzhanghaoActivity extends AppCompatActivity {

EditText et1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jizhuzhanghao);

et1=(EditText)findViewById(R.id.et1);

SharedPreferences sp=getSharedPreferences("a",MODE_PRIVATE);

String s=sp.getString("a",null);
et1.setText(s);
}

public void bt1(View v)
{
String string=et1.getText().toString();
SharedPreferences sharedPreferences=getSharedPreferences("a",MODE_PRIVATE);

SharedPreferences.Editor editor=sharedPreferences.edit();

editor.putString("a",string);

editor.commit();

Toast.makeText(JizhuzhanghaoActivity.this, "记住账户", Toast.LENGTH_SHORT).show();
}
}



原文地址:https://www.cnblogs.com/1ming/p/5522251.html