四大组件之一 -------- 文件存储_文本文件
main.xml
View Code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/authorinfo"
android:textSize="22px"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/ageinfo"
android:textSize="22px"
android:textColor="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
LoadData.java
View Code
package org.lxh.demo;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
public class LoadData extends Activity {
// 文件名称
private static final String FILENAME = "mldnsss";
// 文本显示
private TextView authorInfo = null ;
// 文本显示
private TextView ageInfo = null ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 定义布局管理器
super.setContentView(R.layout.main) ;
this.authorInfo = (TextView) super.findViewById(R.id.authorinfo) ;
this.ageInfo = (TextView) super.findViewById(R.id.ageinfo) ;
// 指定操作的文件名称
SharedPreferences share = super.getSharedPreferences(FILENAME,
Activity.MODE_PRIVATE);
this.authorInfo.setText("作者:" + share.getString("author", "没有作者信息。"));
this.ageInfo.setText("年龄:" + share.getInt("age", 0));
}
}