[android-developers] A clear, concise tutorial on PreferenceActivity Preferences?

2010-06-01 Thread draf...@gmail.com
I was wondering can anyone direct me to a detailed Preferences
tutorial?

Or provide me with a bit of help here?

I have my preferences saved in preferences.xml as follows:

PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/
android
PreferenceCategory android:title=Wifi Settings

EditTextPreference
android:key=edittext_block_attach_err
android:title=@string/title_edittext_preference
android:summary=@string/summary_edittext_preference
android:dialogTitle=@string/
dialog_title_edittext_preference /

/PreferenceCategory

/PreferenceScreen

I then have a preference activity as follows:

public class WlanSettings extends PreferenceActivity {

SharedPreferences prefs;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

addPreferencesFromResource(R.xml.preferences);
prefs = this.getSharedPreferences(CiceroWlanSettings,
Activity.MODE_PRIVATE);


}

This display's the EditTextPreference fine but how do I then set up a
default preference to be displayed in the dialog box that pops up with
an EditTextPreference?

And How do I save changes that occur in my preference activity to my
preferences?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] A clear, concise tutorial on PreferenceActivity Preferences?

2010-06-01 Thread Mark Murphy
draf...@gmail.com wrote:
 I was wondering can anyone direct me to a detailed Preferences
 tutorial?
 
 Or provide me with a bit of help here?
 
 I have my preferences saved in preferences.xml as follows:
 
 PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/
 android
 PreferenceCategory android:title=Wifi Settings
 
 EditTextPreference
 android:key=edittext_block_attach_err
 android:title=@string/title_edittext_preference
 android:summary=@string/summary_edittext_preference
 android:dialogTitle=@string/
 dialog_title_edittext_preference /
 
 /PreferenceCategory
 
 /PreferenceScreen
 
 I then have a preference activity as follows:
 
 public class WlanSettings extends PreferenceActivity {
 
 SharedPreferences prefs;
 
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 
 addPreferencesFromResource(R.xml.preferences);
 prefs = this.getSharedPreferences(CiceroWlanSettings,
 Activity.MODE_PRIVATE);
 
 
 }
 
 This display's the EditTextPreference fine but how do I then set up a
 default preference to be displayed in the dialog box that pops up with
 an EditTextPreference?

android:defaultValue in the XML.

 And How do I save changes that occur in my preference activity to my
 preferences?

It happens automatically.

I don't know what that prefs=this.getSharedPreferences() line is for.
It's not needed, and it's probably reading the wrong file, anyway. Use
PreferenceManager.getDefaultSharedPreferences() for work with the file
that will be used by the PreferenceActivity.

See:

http://github.com/commonsguy/cw-android/tree/master/Prefs/Dialogs/

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 2.0 Available!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] A clear, concise tutorial on PreferenceActivity Preferences?

2010-06-01 Thread Donal Rafferty
Thanks Mark.

To access my preferences outside my PreferenceActivity in another Activity
or a Service can I use PreferenceManager.
getDefaultSharedPreferences() also?

In your code here:

http://github.com/commonsguy/cw-android/blob/master/Prefs/Dialogs/src/com/commonsware/android/prefdialogs/DialogsDemo.java

I see SharedPreferences prefs=PreferenceManager is used, is that correct?
Should I use it like that to retrieve my preferences eslewhere in my
application?

On Tue, Jun 1, 2010 at 4:26 PM, Mark Murphy mmur...@commonsware.com wrote:

 draf...@gmail.com wrote:
  I was wondering can anyone direct me to a detailed Preferences
  tutorial?
 
  Or provide me with a bit of help here?
 
  I have my preferences saved in preferences.xml as follows:
 
  PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/
  android
  PreferenceCategory android:title=Wifi Settings
 
  EditTextPreference
  android:key=edittext_block_attach_err
  android:title=@string/title_edittext_preference
  android:summary=@string/summary_edittext_preference
  android:dialogTitle=@string/
  dialog_title_edittext_preference /
 
  /PreferenceCategory
 
  /PreferenceScreen
 
  I then have a preference activity as follows:
 
  public class WlanSettings extends PreferenceActivity {
 
  SharedPreferences prefs;
 
 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
 
  addPreferencesFromResource(R.xml.preferences);
  prefs = this.getSharedPreferences(CiceroWlanSettings,
  Activity.MODE_PRIVATE);
 
 
  }
 
  This display's the EditTextPreference fine but how do I then set up a
  default preference to be displayed in the dialog box that pops up with
  an EditTextPreference?

 android:defaultValue in the XML.

  And How do I save changes that occur in my preference activity to my
  preferences?

 It happens automatically.

 I don't know what that prefs=this.getSharedPreferences() line is for.
 It's not needed, and it's probably reading the wrong file, anyway. Use
 PreferenceManager.getDefaultSharedPreferences() for work with the file
 that will be used by the PreferenceActivity.

 See:

 http://github.com/commonsguy/cw-android/tree/master/Prefs/Dialogs/

 --
 Mark Murphy (a Commons Guy)
 http://commonsware.com | http://github.com/commonsguy
 http://commonsware.com/blog | http://twitter.com/commonsguy

 _Android Programming Tutorials_ Version 2.0 Available!

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] A clear, concise tutorial on PreferenceActivity Preferences?

2010-06-01 Thread Mark Murphy
Donal Rafferty wrote:
 Thanks Mark.
 
 To access my preferences outside my PreferenceActivity in another
 Activity or a Service can I use PreferenceManager.
 getDefaultSharedPreferences() also?

Yes. That will return the same preferences for this application.

 In your code here:
 
 http://github.com/commonsguy/cw-android/blob/master/Prefs/Dialogs/src/com/commonsware/android/prefdialogs/DialogsDemo.java
 
 I see SharedPreferences prefs=PreferenceManager is used, is that
 correct?

Well, there's more to it than that. You may need to scroll to the right.

I'm going to need to switch to spaces instead of tabs, as my books need
two-space tabs, but GitHub uses eight-space tabs, so my code gets
stretched way out horizontally. :-(

 Should I use it like that to retrieve my preferences eslewhere
 in my application?

Sure.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_
Version 1.5 Available!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en