How do I implement the onClick method for a DialogPreference?

by Nick » Sat, 22 Aug 2009 01:53:28 GMT


Sponsored Links
 I have implemented onSharedPreferenceChanged in my Preference
Activity, which works for other preference settings but it won't get
triggered when I click on the DialogPreference.  I have also tried to
add set the OnPreferenceClickListener to the DialogPreference, which
also works, but this gets triggered as soon as I click on the
preference screen and not on one of the buttons in the actual dialog
window.

I would like to somehow implement the onClick method but don't know
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");

                }
        }
}

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. GLSurfaceview on top on a SurfaceView

Look at this:
http://nhenze.net/?p=172

They show that it is possible to put  an GLSurfaceview on top on a
SurfaceView.

I hope it would be useful.

-- 

2. SQlite Db problems

hai developers,

       i want to know  how to store the images in SQLite database in
android.and also how to retrieve  it.  anyone give the samplecode or
any URL give me to develop my application.

-- 

3. BitmapFactory.decodeStream sometimes returns null

4. service dies without calling onDestroy()

5. Building APPS that require an online database

6. Blank screen displayed after downloading from Android Browser.

7. Using intent with startActivity from inner class