【SharedPreferences存储】SharedPreferences存储方式
来源:互联网 发布:matlab优化工具箱教程 编辑:程序博客网 时间:2024/05/17 17:16
布局文件:main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- 姓名标签 --> <TextView android:id="@+id/nameText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="10px" android:textStyle="bold" android:text="@string/name" /> <!-- 姓名输入框 --> <EditText android:id="@+id/nameEdit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/nameText" android:layout_alignTop="@id/nameText" /> <!-- 电话 --> <TextView android:id="@+id/telText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/nameEdit" android:layout_alignParentLeft="true" android:textStyle="bold" android:text="@string/tel" /> <!-- 电话输入框 --> <EditText android:id="@+id/telEdit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/telText" android:layout_alignTop="@id/telText" /> <!-- 反馈内容 --> <TextView android:id="@+id/contentText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/telEdit" android:layout_alignParentLeft="true" android:textStyle="bold" android:text="@string/content" /> <!-- 反馈输入框 --> <EditText android:id="@+id/contentEdit" android:layout_width="fill_parent" android:layout_height="120px" android:layout_toRightOf="@id/contentText" android:layout_alignTop="@id/contentText" /></RelativeLayout>
MainActivity
import android.app.Activity;import android.content.SharedPreferences;import android.os.Bundle;import android.widget.EditText;import android.widget.TextView; public class MainActivity extends Activity { private EditText nameEdit; private EditText telEdit; private EditText contentEdit; private final String PREFERENCES_NAME = "feedback"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); nameEdit = (EditText) findViewById(R.id.nameEdit); telEdit = (EditText) findViewById(R.id.telEdit); contentEdit = (EditText) findViewById(R.id.contentEdit); SharedPreferences mySharedPreferences = getSharedPreferences( PREFERENCES_NAME, MODE_PRIVATE); nameEdit.setText(mySharedPreferences.getString("name", "")); telEdit.setText(mySharedPreferences.getString("tel", "")); } @Override public void onStop() { SharedPreferences mySharedPreferences = getSharedPreferences( PREFERENCES_NAME, MODE_PRIVATE); SharedPreferences.Editor editor = mySharedPreferences.edit(); editor.putString("name", nameEdit.getText().toString()); editor.putString("tel", telEdit.getText().toString()); editor.commit(); super.onStop(); }}
- 【SharedPreferences存储】SharedPreferences存储方式
- 5 SharedPreferences存储方式
- SharedPreferences数据存储方式
- 存储方式一:SharedPreferences
- Android存储方式-SharedPreferences
- 数据存储方式(SharedPreferences)
- Andorid存储方式----SharedPreferences存储
- SharedPreferences存储
- SharedPreferences存储
- SharedPreferences存储
- SharedPreferences存储
- SharedPreferences 存储
- SharedPreferences存储
- SharedPreferences存储
- SharedPreferences存储
- SharedPreferences存储
- SharedPreferences存储
- SharedPreferences存储
- 分享我的“艺术品”:公共建筑能耗监测平台的GPRS通讯服务器的开发方法分享
- linux 时区调整
- 基于MSCOMM控件串口通讯(MFC)
- 《向朋友借钱》:一个发人深省的故事
- [珠玑之椟]字符串和序列:左移、哈希、最长重复子序列的后缀数组解法、最大连续子序列
- 【SharedPreferences存储】SharedPreferences存储方式
- alibaba druid 的配置
- 彻底理解PHP的SESSION机制
- 查看mysql最早的binlog文件编号
- UBUNTU10.04 配置Eric5 + python3.1
- CSS样式中 绝对定位和相对定位
- C++基础知识整理拾遗
- 正则表达式——环视
- H.264优化方向