I'm writing a simple android app which needs to store 2 childrens details, i.e. name, age, toy. I was planning to do this using sharedpreferences. Here's my xml:
prefs.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceScreen android:title="Edit Child Details">
<PreferenceScreen android:title="Edit Child 1 Details">
<EditTextPreference android:title="Name" android:dialogTitle="Name of Child 1" android:key="name1" />
<EditTextPreference android:title="Age" android:dialogTitle="Age of Child 1" android:key="age1" />
<EditTextPreference android:title="Toy" android:dialogTitle="Toy of Child 1" android:key="toy1" />
</PreferenceScreen>
<PreferenceScreen android:title="Edit Child 2 Details">
<EditTextPreference android:title="Name" android:dialogTitle="Name of Child 2" android:key="name2" />
<EditTextPreference android:title="Age" android:dialogTitle="Age of Child 2" android:key="age2" />
<EditTextPreference android:title="Toy" android:dialogTitle="Toy of Child 2" android:key="toy2" />
</PreferenceScreen>
<ListPreference android:entries="@array/child_array" android:entryValues="@array/child_array" android:key="child_selector" android:title="Select Child"/>
</PreferenceScreen>
strings.xml
<string-array name="child_array">
<item >1</item>
<item >2</item>
</string-array>
I know this could be better in sqllite database or local storage, but its only a basic app and I'm still a beginner.
What I'm trying to do in the code is then query the child_selector (i.e. user will select either child 1 or 2) preference and then I read the respective childs details for my app.
Not too sure if this is the best way to do things, so any advice would be welcome as I'm unsure how to reference the childs details. I'm have some basic unix scripting skills and I know this isn't an array, but not sure if its even feasable to use the java equivalent of ${string}[$number]