zoukankan      html  css  js  c++  java
  • 数据存储课后作业

    package com.example.wang.myapplication;
    
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;
    import android.view.View;
    import android.widget.EditText;
    
    public class ZuoyeActivity5 extends AppCompatActivity {
    
        EditText user_name;
        EditText user_password;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_zuoye5);
            user_name=(EditText)findViewById(R.id.user_name);
            user_password=(EditText)findViewById(R.id.user_password);
    
            SharedPreferences sharedPreferences1 =getSharedPreferences("cunchu",MODE_APPEND);
            String string = sharedPreferences1.getString("用户名", "未添加");
            Log.e("TAG","string="+string);
            user_name.setText(string);
        }
        public  void bt1_OnClick(View v)
        {
            String username=user_name.getText().toString();
            String userpassword=user_password.getText().toString();
    
    
                SharedPreferences sharedPreferences=getSharedPreferences("cunchu", MODE_APPEND);
    
                SharedPreferences.Editor editor=sharedPreferences.edit();
    
                editor.putString("用户名",username);
                editor.putString("用户密码", userpassword);
    
                editor.commit();
                Log.e("TAG","username="+username);
                Log.e("TAG", "userpassword="+userpassword);
    
    
        }
        public  void bt2_OnClick(View v)
        {
           finish();
        }
    }
    java
    <?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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.wang.myapplication.ZuoyeActivity5"
        android:orientation="vertical">
        
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="用户名"
            android:id="@+id/user_name"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="密码"
            android:inputType="numberPassword"
            android:id="@+id/user_password"/>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="登陆"
                android:onClick="bt1_OnClick"/>
            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="关闭"
                android:onClick="bt2_OnClick"/>
        </LinearLayout>
    
    </LinearLayout>
    xml

  • 相关阅读:
    npm命令
    前端单元测试工具karma和jest
    加解密学习之--模运算与经典密码学
    数据结构之-翻转二叉树
    数据结构之-链表倒转
    转载:MQ
    分布式ID生成器 待整理
    软件开发中的负载均衡
    制作软件过程中所产出的文档(请补充)
    多线程的创建
  • 原文地址:https://www.cnblogs.com/wangchuanqi/p/5520641.html
Copyright © 2011-2022 走看看