码迷,mamicode.com
首页 > 移动开发 > 详细

Android xml文件解析(getSharedPreferences)

时间:2016-02-25 21:23:27      阅读:421      评论:0      收藏:0      [点我收藏+]

标签:

package com.itheima.share;

import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
private EditText ed_qqnumber;
private EditText ed_qqpassword;
private CheckBox cbx;
private SharedPreferences sp;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed_qqnumber = (EditText) findViewById(R.id.qqnumber);
ed_qqpassword = (EditText) findViewById(R.id.qqpassword);
cbx = (CheckBox) findViewById(R.id.remember);
sp = getSharedPreferences("config", MODE_PRIVATE);
String num = sp.getString("number", "");
String pwd = sp.getString("password", "");
ed_qqnumber.setText(num);
ed_qqpassword.setText(pwd);
}

public void login(View v) {
String number = ed_qqnumber.getText().toString().trim();
String password = ed_qqpassword.getText().toString().trim();
if (TextUtils.isEmpty(number) || TextUtils.isEmpty(password)) {

// 给 用户提示, 输入 号码 和 密码
Toast.makeText(this, "请输入 qq号码 和密码 ", 0).show();
return;
}
else {
sp =getSharedPreferences("config", 0);
Editor editor=sp.edit();
editor.putString("number", number);
editor.putString("password", password);
editor.commit();
}

}
}

Android xml文件解析(getSharedPreferences)

标签:

原文地址:http://www.cnblogs.com/wswbk/p/5218260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!