views:

1501

answers:

4

Is there any way to add a button to the bottom of preferences screen and make them work correct when scrolling?

A: 

Is there any way to add a button to the bottom of preferences screen and make them work correct when scrolling?

I do not completely understand the question, but I suspect the answer is "no".

The preference screen itself is made up of preferences, period. If you want something else on the screen, add a preference, as Prashast suggested.

You can implement an option menu, though, via your PreferenceActivity subclass.

CommonsWare
A: 
Walkor
+4  A: 

There is another solution for customizing the appearance of the preferences.

Design a normal XML layout with buttons or whatever you want to add to the standard preferences. Include a ListView in your layout and give it the ID @android:id/list.

Let's say we call the layout file res/layout/main.xml. It could look something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical">
    <Button android:text="This is a button on top of all preferences."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    <ListView android:id="@android:id/list"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" />
</LinearLayout>

In your PreferenceActivity, add these two lines to your onCreate:

addPreferencesFromResource(R.xml.preferences);
setContentView(R.layout.main);

The ListView in your layout will then be replaced by the preferences defined the usual way in res/xml/preferences.xml.

Max
I'll keep it in mind, thanks.
Walkor
A: 

I've try this code , but Button is not in bottom of preference, and when I add PreferenceScreen pref3 and pref4, Button : Done & Revert is coved

mailoan1909
I don't have IDE in my hands right now to test, but I had there about 6-7 different options and it works fine. Maybe you are using wrong ListView? I used the one, posted in the answer below. Double check it please.
Walkor