安卓保存数据的三种方式--Rom、SD、sharepreference

这篇博客主要介绍了安卓开发中初学者应掌握的三种数据存储方式:1) 存储在ROM中,2) 使用SD卡存储,以及3) 通过SharedPreferences进行轻量级数据保存。通过示例,演示了如何在虚拟机的SD卡目录下查看登录信息。
摘要由CSDN通过智能技术生成

下面我将讲一下初学者应该掌握的安卓保存数据的三种方式

要求:做一个登录的界面,用户可以输入账号和密码,有确定的按钮,有一个记住密码的勾选框,若用户在选择记住密码后,下次登录时账号密码仍然存在,不需要用户再次输入。界面如下
 
恩,布局十分的简单,我就不废话了,直接贴出代码,来看下activity_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"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/user" />

    <EditText
        android:id="@+id/ed_user"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="请输入你的账号"
        android:inputType="text" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/password" />

    <EditText
        android:id="@+id/ed_password"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="请输入你的密码"
        android:inputType="textPassword" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <CheckBox
            android:id="@+id/cb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/remember_password" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:onClick="login"
            android:text="@string/yes" />
    </RelativeLayout>

    <RadioGroup
        android:id="@+id/rd_findlocation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/rd_rom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/rom" />

        <RadioButton
            android:id="@+id/rd_sd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值