I dont have an IDE in front of me, but I think this exact example is
available in the API Demos. Add it to your Eclipse workspace and poke around
in the preference area. I advise you to install the ApiDemos on your
emulator or test phone (or G1 if you have one). It makes life alot easier
when you see what you want, then the task is just finding it in the demos
(which is easy).



On Fri, Aug 21, 2009 at 1:54 PM, Nick <nick.vers...@gmail.com> wrote:

>
> Looking around the source I think I found what I was looking for.  I
> assume that I need to implement onDialogClosed from
> DialogPreference.java.  But to do this do I need to create a new class
> say MyDialogPreference or is there a way to just implement that method
> in the class below?
>
>
> On Aug 20, 3:55 pm, Nick <nick.vers...@gmail.com> wrote:
> > I have a DialogPreference in my Preference Activity and would like to
> > know which button was pressed. I have implemented the
> > OnSharedPreferenceChangeListener which does not seem to get triggered
> > when the DialogPreference is selected.   I have also tried
> > OnPreferenceClickListener but this gets triggered as soon as the
> > DialogPreference is clicked from the main screen and not when one of
> > the actual dialog buttons was pressed.  was.
> >
> > So I think I need to implement onClick for this dialog but I am not
> > sure where to do this.
> >
> > public class Preferences extends PreferenceActivity implements
> > OnSharedPreferenceChangeListener {
> >
> >         private static final String LOG = "test";
> >         private DialogPreference mfactory;
> >
> >         @Override
> >         protected void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >
> >         // Load the preferences from an XML resource
> >         addPreferencesFromResource(R.xml.preferences);
> >
> >         mfactory = (DialogPreference)findPreference("pref_factory");
> >         mfactory.setOnPreferenceClickListener(new
> > DialogPreference.OnPreferenceClickListener() {
> >
> >                         @Override
> >                         public boolean onPreferenceClick(Preference
> preference) {
> >                                 Log.i(LOG, "onPreferenceClick1 entered");
> >
> >                                 // TODO Auto-generated method stub
> >                                 return false;
> >                         }});
> >     }
> >
> >         @Override
> >         protected void onResume() {
> >                 super.onResume();
> >                 Log.i(LOG, "onResume entered");
> >
> >                 // Add a Listener
> >                 getPreferenceScreen().getSharedPreferences
> > ().registerOnSharedPreferenceChangeListener(this);
> >         }
> >
> >         @Override
> >         protected void onPause() {
> >                 super.onPause();
> >                 Log.i(LOG, "onPause entered");
> >
> >                 // Remove the Listener
> >                 getPreferenceScreen().getSharedPreferences
> > ().unregisterOnSharedPreferenceChangeListener(this);
> >         }
> >
> >         public void onSharedPreferenceChanged(SharedPreferences
> > sharedPreferences, String key) {
> >                 Log.i(LOG, "onSharedPreferenceChanged entered");
> >                     if (key.contains("seekbar")) {
> >                     }
> >                 }
> >         }
> >
> > }
> >
> >
> >
>


-- 
Donn
http://blog.donnfelker.com/

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

Reply via email to