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. Find tools on windows

In android sdk for windows, cant find tools like dexdump.exe,
dexlist.exe and dexopt.exe.

Can any one provide these tools for me?

2. How to kill an ImageView?... thx

Hey All,

I'm trying to transition from my main splash screen to the next part
of my code.  How do I kill my splash screen?...  In my main.xml the
splash screen image is simply:

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/my_image"
     />

directly under the <Imageview in my main.xml file I have <TextViews
and <Spinners.  Does the <Imageview portion of my text need to reside
in a different .xml file?...

The Dev Guide suggests using an expand_collapse.xml, which is fine,
but I'm not sure where to place the bottom part of that tutorial
section:

<With this XML saved in the file res/drawable/expand_collapse.xml, the
following code will instantiate the TransitionDrawable and set it as
the content of an ImageView:

Resources res = mContext.getResources();TransitionDrawable transition
= (TransitionDrawable) res.getDrawable
(R.drawable.expand_collapse);ImageView image = (ImageView) findViewById
(R.id.toggle_image);image.setImageDrawable(transition);>

Is this a seperate .java file?  How do these pieces fit together?

Thx in advance!

D

3. Seek the leb128's beb128 counterpart

4. Getting cell signal strength for current cell vs neighboring cells

5. For those following the AndAppStore / Archos dispute.

6. multi resolution image button selectors broken?

7. Sending market link in mail