I'm trying to build an app where someone can fill in their personal data like their name, telephone number, Email...
For each field mentioned above, I created an EditText
. Now my goal is to save the user's input using SharedPreferences
so that he/she don't have to fill it up every time they reopen the app.
The codes I've found take care of saving the data for one EditText
only (Save entered text in editText via button). How can I achieve that on multiple EditText
fields?
This is my XML file below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vul dit compleet in"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Naam: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:textStyle="bold"/>
<EditText
android:id="@+id/edit_Naam"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:hint="Vul uw naam in"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Functie: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:textStyle="bold"/>
<EditText
android:id="@+id/edit_Functie"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:hint="Vul uw functie in"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Personeelsnummer "
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:textStyle="bold"/>
<EditText
android:id="@+id/edit_Plnr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:hint="Vul uw plnr in"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:textStyle="bold"/>
<EditText
android:id="@+id/edit_Email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:hint="NS mail"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telefoon: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:textStyle="bold"/>
<EditText
android:id="@+id/edit_Telefoon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000066"
android:hint="zonder +31"/>
<Button
android:id="@+id/button_Opslaan"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/edit_Bericht"
android:layout_centerHorizontal="true"
android:layout_marginBottom="48dp"
android:layout_weight="0.03"
android:background="#009CDE"
android:drawableLeft="@drawable/ic_launcher"
android:text="Opslaan"
android:textColor="#FFFFFF"/>
</LinearLayout>
</ScrollView>