1

I just start to study android, so have some problem

i have a file res/xml/settings.xml - settings from menu create class Prefs and try to use settings from file above

package org.example.sudoku;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Prefs extends PreferenceActivity {
       @Override
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          addPreferencesFromResource(R.xml.settings);
       }
    }

Problem, that addPreferencesFromResource cant be used and i need to use preferencesResId (according to comments), but if i write something like this

     preferencesResId(R.xml.settings);

its not good.

Where is error in code? Could any1 help? Also i try to learn android by using book - Hello Android.

hbk
  • 10,908
  • 11
  • 91
  • 124

1 Answers1

0

preferencesResId() is not a method, it is a placeholder in conversation for your resource id (R.xml.settings).

So although

addPreferencesFromResource(R.xml.settings);

Is deprecated, if you're using this approach, this is still the most correct way - there isn't another way using the deprecated approach.

I suggest you look at this SO question - it tells you what you should be using instead (PreferenceFragments). If you need a code sample, fire up Eclipse and the ADT plugin and make a SettingsActivity via the new Activity Wizard.

And as usual, here is the full JavaDoc for PreferenceActivity.

Community
  • 1
  • 1
A--C
  • 36,351
  • 10
  • 106
  • 92
  • many thanks for fast reply... need to reed a little bit more information and try – hbk Jan 25 '13 at 20:20
  • @Bki Welcome to SO! And, exactly, trying is everything :-) If you haven't done so already, I also suggest reading the [Java](http://docs.oracle.com/javase/tutorial/) tutorials as well as the [Android](http://developer.android.com/training/basics/firstapp/index.html) tutorials. Then if you're stuck and it's a good question, make a new question on SO - we like to answer [good questions](http://stackoverflow.com/faq#questions). – A--C Jan 25 '13 at 20:25
  • i reread all writed code and in additional recomended by you link - as result - i catch idea, found errors and fix it - now its ok. Many thanks for your help . also this http://www.brighthub.com/mobile/google-android/articles/28673.aspx was usefull too – hbk Jan 26 '13 at 13:39