package com.test;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
*
* @author Administrator
* SharedPreferences的存储方法
* getSharedPreferences(SETTING_INFOS, 0);
* settings.edit()……
* 获取手机屏幕大小
*/
public class TestDemo extends Activity {
public static final String SETTING_INFOS = "SETTING_Infos";
public static final String NAME = "NAME";
public static final String PASSWORD = "PASSWORD";
private EditText field_name;
private EditText field_pass;
private Button field_button;
private Button field_buttonScreen;
private TextView field_view;
private TextView field_viewScreen;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
field_name = (EditText) findViewById(R.id.name);
field_pass = (EditText) findViewById(R.id.password);
field_button = (Button) findViewById(R.id.button_show);
field_view = (TextView) findViewById(R.id.view_show);
field_viewScreen = (TextView) findViewById(R.id.button_showScreen);
field_buttonScreen = (Button) findViewById(R.id.button_getScreen);
SharedPreferences settings = getSharedPreferences(SETTING_INFOS, 0);
String name = settings.getString(NAME, "");
String password = settings.getString(PASSWORD, "");
field_view.setText("你原来的帐号是:"+name+"\n密码是:"+password);
field_button.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v) {
field_view.setText("你刚输入的帐号是:"+field_name.getText().toString()+"\n密码是:"+field_pass.getText().toString());
}
}
);
field_buttonScreen.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v)
{
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
//获得手机的宽带和高度像素单位为px
String str = "手机屏幕分辨率为:" + dm.widthPixels
+" * "+dm.heightPixels;
field_viewScreen.setText(str);
}
});
field_name.setText(name);
field_pass.setText(password);
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
SharedPreferences settings = getSharedPreferences(SETTING_INFOS, 0);
settings.edit()
.putString(NAME, field_name.getText().toString())
.putString(PASSWORD, field_pass.getText().toString())
.commit();
}
}
fw5454f
- 粉丝: 3
- 资源: 10
最新资源
- 快速定制中国传统节日头像(源码)
- hcia 复习内容的实验
- 准Z源光伏并网系统MATLAB仿真模型,采用了三次谐波注入法SPWM调制,具有更高的电压利用效率 并网部分采用了电压外环电流内环 电池部分采用了扰动观察法,PO Z源并网和逆变器研究方向的同学可
- 海面目标检测跟踪数据集.zip
- 欧美风格, 节日主题模板
- 西门子1200和三菱FXU通讯程序
- 11种概率分布的拟合与ks检验,可用于概率分析,可靠度计算等领域 案例中提供11种概率分布,具体包括:gev、logistic、gaussian、tLocationScale、Rayleigh、Log
- 机械手自动排列控制PLC与触摸屏程序设计
- uDDS源程序publisher
- 中国风格, 节日 主题, PPT模板
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈