package com.example.day10_26;import java.util.Map;import androID.os.Bundle;import androID.support.v7.app.ActionBaractivity;import androID.text.TextUtils;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.Toast;public class MainActivity extends ActionBaractivity { private EditText et1; private EditText et2; private button bu1; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); et1 = (EditText) findVIEwByID(R.ID.et1); et2 = (EditText) findVIEwByID(R.ID.et2); bu1 = (button) findVIEwByID(R.ID.bu1); Map<String, String> userInfo = SPSaveQQ.getUserInfo(this); if (userInfo != null) { et1.setText(userInfo.get("account")); et2.setText(userInfo.get("pasSEOrd")); } } public voID Click(VIEw vIEw) { // Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT); switch (vIEw.getID()) { case R.ID.bu1: String account = et1.getText().toString().trim(); String password = et2.getText().toString(); if (TextUtils.isEmpty(account)) { Toast.makeText(MainActivity.this, "请输入QQ账号", Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(password)) { Toast.makeText(MainActivity.this, "请输入密码", Toast.LENGTH_SHORT).show(); return; } Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show(); boolean isSaveSuccee = SPSaveQQ.saveUserInfo(MainActivity.this, account, password); if (isSaveSuccee) { Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "保存失败", Toast.LENGTH_SHORT).show(); } break; default: break; } }}
package com.example.day10_26;import java.io.fileinputStream;import java.io.fileNotFoundException;import java.io.fileOutputStream;import java.io.IOException;import java.util.HashMap;import java.util.Map;import androID.content.Context;import androID.content.SharedPreferences;public class SPSaveQQ { /** * 保存数据 * * @param context * @param account * @param password * @return */ public static boolean saveUserInfo(Context context, String account, String password) { SharedPreferences sp = context.getSharedPreferences("data", Context.MODE_PRIVATE); SharedPreferences.Editor edit = sp.edit(); edit.putString("username", account); edit.putString("pwd", password); edit.commit(); return true; } public static Map<String, String> getUserInfo(Context context) { SharedPreferences sp = context.getSharedPreferences("data", Context.MODE_PRIVATE); String account = sp.getString("username", null); String password = sp.getString("pwd", null); Map<String,String> userMap = new HashMap<String, String>(); userMap.put("account", account); userMap.put("pasSEOrd", password); return userMap; }}
<relativeLayout 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.homework2.MainActivity" > <TextVIEw androID:ID="@+ID/tv1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="90dp" androID:text="账号" androID:textSize="30sp" androID:background="#FFFFFF" /> <EditText androID:ID="@+ID/et1" androID:layout_wIDth="200sp" androID:layout_height="wrap_content" androID:layout_alignBottom="@+ID/tv1" androID:layout_alignParentRight="true" androID:layout_aligntop="@+ID/tv1" androID:layout_toRightOf="@+ID/tv1" androID:phoneNumber="true" androID:background="#FFFFFF" androID:textSize="20sp" > </EditText> <TextVIEw androID:ID="@+ID/tv2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="140sp" androID:text="密码" androID:textSize="30sp" androID:background="#FFFFFF" /> <EditText androID:ID="@+ID/et2" androID:layout_wIDth="200sp" androID:layout_height="wrap_content" androID:layout_alignBottom="@+ID/tv2" androID:layout_alignParentRight="true" androID:layout_aligntop="@+ID/tv2" androID:layout_toRightOf="@+ID/tv2" androID:password="true" androID:background="#FFFFFF" androID:textSize="20sp" > </EditText> <TextVIEw androID:ID="@+ID/tv3" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_below="@+ID/bt1" androID:layout_centerHorizontal="true" androID:layout_margintop="98dp" androID:textSize="30sp" /> <ImageVIEw androID:layout_wIDth="45sp" androID:layout_height="45sp" androID:layout_above="@+ID/et1" androID:layout_centerHorizontal="true" androID:src="@drawable/ic_launcher" androID:layout_marginBottom="18dp" /> <button androID:ID="@+ID/bu1" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_alignleft="@+ID/tv2" androID:layout_below="@+ID/tv2" androID:layout_margintop="69dp" androID:background="#63B8FF" androID:onClick="Click" androID:text="登录" androID:textSize="30sp" /> </relativeLayout>
@H_502_7@
@H_502_7@@H_502_7@总结
以上是内存溢出为你收集整理的Day10_27全部内容,希望文章能够帮你解决Day10_27所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)