Android List Of Preference
Android List Of Preference
2.EditTextPreference :This preference will store a string into the SharedPreferences.
3.CheckBoxPreference : This preference will store a boolean into the SharedPreferences.
4.RingtonePreference :
5.MultiSelectListPreference
6.DialogPreference
Screen Shot
Android List Of Preference
1.ListPreference :
This preference will store a string into the SharedPreferences. This string will be the value
from the setEntryValues(CharSequence[])
array.2.EditTextPreference :This preference will store a string into the SharedPreferences.
3.CheckBoxPreference : This preference will store a boolean into the SharedPreferences.
4.RingtonePreference :
5.MultiSelectListPreference
6.DialogPreference
Screen Shot
Activity Code:
import
android.os.Bundle;
import
android.preference.PreferenceActivity;
public
class
AndroidQAActivity extends
PreferenceActivity {
@Override
public
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.main);;
}
}
Resource Code
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="Android"
android:title="Android
Preference"
android:summary="List
of Version">
<PreferenceCategory
android:title="List
Preference">
<ListPreference
android:key="Android"
android:title="Android
List of Version"
android:summary="Cool
List of Version"
android:entries="@array/androidversion"
android:entryValues="@array/androidversion_values"
android:dialogTitle="List
of Version"
android:defaultValue="List
of Version" />
</PreferenceCategory>
<PreferenceCategory
android:title="Edit
Preference">
<EditTextPreference
android:key="Android"
android:title="Edit
Preference"
android:summary="Edit
Text"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="RingTone
Preference">
<RingtonePreference
android:key="Android"
android:title="RingTone
Preference"
android:summary="RingTone
Preference"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="CheckBox
Preference">
<CheckBoxPreference
android:key="1"
android:title="CheckBox
Preference"
android:summary="CheckBox
Preference"
/>
</PreferenceCategory>
</PreferenceScreen>
String Code
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<resources>
<string-array
name="androidversion">
<item>Android
1.6</item>
<item>Android
2.1</item>
<item>Android
2.2</item>
<item>Android
2.3</item>
<item>Android
3.0</item>
<item>Android
4.0.1</item>
</string-array>
<string-array
name="androidversion_values">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
</string-array>
I am not clear with this post. What is the use of this preference list. Generally we use shared preference in our activity and store value to it. Than define it in xml doesn't provide any sense to me. Please help me with this. Please explain use of this article in project or any app...
ReplyDelete