0

I have a preference activity which gets it's layout from the following XML. This makes a button appear at the bottom of the preferences.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/com.stealthcopter.nexus.nexusgl"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
<ListView android:id="@android:id/list"
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
<Button android:text="This is a button on top of all preferences."
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />         
</LinearLayout>

However when open a nested PreferenceScreen inside it reverts to the showing just a listview, is there a simple way to keep the layout the same between the preference screens?

I tried PreferenceScreen.setLayoutResource(R.id.layout.main); but that just changes the view displayed before it is opened

Update

I fixed (Kludged) this by changing the nested PreferenceScreens into normal preferences and overriding their onclick methods to clear the preferences from the listview and reload the preferences from an appropriate XML file.

stealthcopter
  • 13,964
  • 13
  • 65
  • 83

2 Answers2

1

I believe that this is another symptom of the bug described here A work around is to reset the layout each time a preference screen is opened.

stealthcopter
  • 13,964
  • 13
  • 65
  • 83
  • And is there a general way to catch this event, like overriding an onSmth method? Or do I have to set a listener for every PreferenceScreen item (and will it work, because the listener might be called before the screen is actually opened)? – lapis Aug 13 '11 at 19:58
  • 1
    I looked into the sources: we have to set a listener for every PreferenceScreen item, and we have to manually handle switching between screens in order to change their appearance because every nested PreferenceScreen opens a new Dialog, so our activity doesn't know anything about it and can't change it. – lapis Aug 13 '11 at 23:13
0

What are you trying to achieve with the custom preference screen? The is no preference to take into account here? I also I'm pretty sure that preference layout have to be in a 'xml' folder not the 'layout'

ahodder
  • 11,353
  • 14
  • 71
  • 114
  • The preference screen fills a list view with preferences, usually non is provided so it just creates a listview for you. If you define a layout for your preference screen it will use that instead (you must include a listview with the id of @android:id/list that it can populate) – stealthcopter Jan 28 '11 at 13:30