zoukankan      html  css  js  c++  java
  • 四大组件之一 文件存储_文本文件

    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));
    }
    }


     

  • 相关阅读:
    grafana+mysql忘记admin密码解决方法
    grafana 的配置文件,和使用mysql数据库做持久化
    贴两个mysql优化的配置文件
    Zabbix监控win10系统
    zabbix监控mysql
    http状态码-备查
    安卓移动端line-height垂直居中出现偏移的解决方法
    Video 自动播放
    渐进式Web应用(PWA)
    基于svg的环形进度条
  • 原文地址:https://www.cnblogs.com/androidsj/p/2416176.html
Copyright © 2011-2022 走看看