We can create PreferenceActivity with header and Fotter.
We shoud make following files and call method.
- Create Layout with ListView.
- Create Preference XML.
- Call setContentView() and addPreferencesFromResource() in onCreate().
Create Layout with ListView
Make layout xml file , to set PreferenceActivity#setContentView().It must have ListView with android:id="@+id/android:list".
you shoud add android:layout_height="0.0dp"and android:layout_weight="1" to ListView, because to show footer in bottom
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <? xml version = "1.0" encoding = "utf-8" ?> android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:orientation = "vertical" > <!-- Header --> < LinearLayout android:id = "@+id/linearLayout2" android:layout_width = "match_parent" android:layout_height = "wrap_content" android:orientation = "vertical" > < TextView android:id = "@+id/textView2" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "Header" android:textAppearance = "?android:attr/textAppearanceLarge" /> </ LinearLayout > <!-- Show Preference in ListView --> < ListView android:id = "@+id/android:list" android:layout_width = "match_parent" android:layout_height = "0.0dp" android:layout_weight = "1" > </ ListView > <!-- Footer --> < LinearLayout android:id = "@+id/linearLayout1" android:layout_width = "match_parent" android:layout_height = "wrap_content" android:orientation = "vertical" > < TextView android:id = "@+id/textView1" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "Footer" android:textAppearance = "?android:attr/textAppearanceLarge" /> </ LinearLayout > </ LinearLayout > |
Create Preference XML
Create Preference XML.Sample.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <? xml version = "1.0" encoding = "utf-8" ?> < CheckBoxPreference android:key = "checkbox_preference" android:summary = "summary_checkbox_preference" android:title = "checkbox_preference" /> < EditTextPreference android:dialogTitle = "dialog_title_edittext_preference" android:key = "edittext_preference" android:summary = "summary_edittext_preference" android:title = "title_edittext_preference" /> < PreferenceScreen android:summary = "intent_preference" android:title = "intent_preference" > < intent android:action = "android.intent.action.VIEW" </ PreferenceScreen > </ PreferenceScreen > |
Call setContentView() and addPreferencesFromResource() in onCreate()
You must call setContentView(YOUR_LAYOUT_WIHT_HEADER_FOOTER_ID).1 2 3 4 5 6 7 | @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); addPreferencesFromResource(R.xml.pref); } |
This article does a lot of help
ReplyDeleteThanks Man.
ReplyDeleteThis served as a perfect starting point for customizing my pref page.
keep up the good work.
Thanks a lot!
ReplyDeleteI have a problem. On preview all is fine, but when I run the aplivatio, the list view fit all the screen, and the footer stay beyond the list.
ReplyDeleteThanks!
How can I fix this ??
I have a problem. On preview all is fine, but when I run the aplivatio, the list view fit all the screen, and the footer stay beyond the list.
ReplyDeleteThanks!
How can I fix this ??