下面我将讲一下初学者应该掌握的安卓保存数据的三种方式
要求:做一个登录的界面,用户可以输入账号和密码,有确定的按钮,有一个记住密码的勾选框,若用户在选择记住密码后,下次登录时账号密码仍然存在,不需要用户再次输入。界面如下
恩,布局十分的简单,我就不废话了,直接贴出代码,来看下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"