• 存储


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.hanqi.zuoyee.cunchu_denglu">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入账号"
        android:id="@+id/et1"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入密码"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="登录"
            android:onClick="b1"/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="注册"/>
    </LinearLayout>
    </LinearLayout>

    layout文件

    package com.hanqi.zuoyee;
    
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.EditText;
    
    public class cunchu_denglu extends AppCompatActivity {
        EditText et;
        String zh;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_cunchu_denglu);
            et=(EditText)findViewById(R.id.et1);
            SharedPreferences s=getSharedPreferences("a",MODE_PRIVATE);
            zh=s.getString("zhanghao",null);
            if(zh!=null){
                et.setText(zh);
            }
        }
        public void b1(View v){
            SharedPreferences s=getSharedPreferences("a", MODE_PRIVATE);
            SharedPreferences.Editor editor = s.edit();
           zh=et.getText().toString();
            if(zh.trim().length()==0){
                return;
            }
            editor.putString("zhanghao",zh);
            editor.commit();
    
        }
    }
  • 相关阅读:
    Adobe PS
    深入学习二叉树(04)平衡二叉树
    深入学习二叉树(03)二叉查找树
    C 知识点
    实战【docker 镜像制作与使用】
    从0到1了解 CI/CD
    单例模式的几种实现方式,使用场景以及优缺点
    设计模式之策略模式浅谈以及简单例子
    WPF几种渐变色
    Linq学习以及简单用法
  • 原文地址:https://www.cnblogs.com/storm47/p/5520388.html
Copyright © 2020-2023  润新知