LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

android采用SharedPreferences保存用戶偏好設(shè)置參數(shù)

admin
2013年2月25日 23:27 本文熱度 4553

 android中SharedPreferences最常被用來保存用戶的一些個(gè)人配置。
1、main.xml
<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"
>

<TextView
android:text="姓名"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/et_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>

<TextView
android:text="密碼"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/et_pwd"
android:password="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>

<Button
android:id="@+id/bt_save"
android:text="保存"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/bt_read"
android:text="讀取"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>



2、MainActivity.java
public class MainActivity extends Activity {

private Button bt_save,bt_read;
private EditText et_name,et_pwd;

private ShareService ss;

private String name,pwd;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

bt_save = (Button) this.findViewById(R.id.bt_save);
bt_read = (Button) this.findViewById(R.id.bt_read);
et_name = (EditText) this.findViewById(R.id.et_name);
et_pwd = (EditText) this.findViewById(R.id.et_pwd);
ss = new ShareService(this);
bt_save.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

name = et_name.getText().toString();
pwd = et_pwd.getText().toString();
ss.save(name,pwd);
et_name.setText("");
et_pwd.setText("");
}
});
bt_read.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
Map<String, String> map = ss.read();
et_name.setText(map.get("name"));
et_pwd.setText(map.get("password"));
}
});

}
}



3、ShareService.java
public class ShareService {

private Context context;
private SharedPreferences preferences = null;


public ShareService(Context context) {
this.context = context;
}

public void save(String name, String pwd) {
preferences = context.getSharedPreferences("temp", Context.MODE_PRIVATE);
Editor editor = preferences.edit();
editor.putString("name", name);
editor.putString("password", pwd);
editor.commit();
}

public Map<String, String> read(){
Map<String, String> map = new HashMap<String, String>();
preferences = context.getSharedPreferences("temp", Context.MODE_PRIVATE);

map.put("name", preferences.getString("name", "isEnmpty"));
map.put("password", preferences.getString("password", "isEnmpty"));
return map;

}

}


該文章在 2013/2/25 23:27:18 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲(chǔ)管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
三级中文字幕在线视频 | 久久成人免费视频这里都有 | 亚洲欧美专区中文字幕 | 色色资源网一区二区免费 | 直接在线看黄AV免费观看 | 五月婷婷丁香综合中文字幕 |