Preferencias básicas Android

Hello this is my first post. Basically I'm a noobie Android developer and I've been working on a live wallpaper over the last couple of weeks.

I've completed the live wallpaper but I'd like to add some functionality via customization. I've spend about 4-5 days trying to get my "Settings" button to work. I've tried shared preferences from the Google API cube_settings which seemed very complicated for a settings menu.

I've copied various pieces of code and modified them to my app without success. I'm on the verge of giving up (Since I work 9-5 and I've been doing this 5:15 till 12 every night without success, very frustrating)

What I want to have is for the settings "page" to load up the XML layout, so far I've got this:

xml/settings.xml : This part points the "settings button" towards my java class Settings.java or at least I think it does.

android:settingsActivity="com.forwardapps.functions.Settings"

Once in this class I've got no idea what to do with it, I've tried many many different things such as setContentView etc etc.

Every time I press the settings button I get the error: "The Application Live Wallpaper Picker (process com.android.wallpaper.livepicker) has stopped..."

Settings works in my other live wallpapers on the phone.

The logcat give's me this error:

02-01 22:29:09.631: E/AndroidRuntime(24491): java.lang.IllegalStateException: Could not execute method of the activity

My settings.xml is basically:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>

Can anyone show me how I can get the layout to show (simplest means possible) or atleast give me a good tutorial that doesn't throw me in the deep end like most of the Google ones.

Any help would be much appreciated because I've spend so much time just trying to get this little bit of my app working, I wish Google had made a better IDE for novices too use as I don't have time to read books that are 600 pages long :-(

Thanks Olly

preguntado el 01 de febrero de 12 a las 22:02

1 Respuestas

try using PrefrenceScreen.

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <CheckBoxPreference
      android:title="@string/<your_string>"
      android:summary ="@string/<your_string>"
      android:key="@string/<your_key>"
      android:defaultValue="false"/>
</PreferenceScreen>

Para más información: http://developer.android.com/reference/android/preference/PreferenceScreen.html

Respondido 02 Feb 12, 02:02

I can just add this by itself? nothing else needed? - Oliver Dixon

You need to use 'extends PreferenceActivity' instead normal Activity and call addPreferencesFromResource(R.xml.<your_preference_file>)....this should load all prefrence in the layout...keep your xml in a new resource folder 'xml'...as it is strictly speajing doesn't give a layout... - Navin Ilavarasan

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.