I found that if I implement onSharedPreferenceChangeListener, findViewById 
works inside the implemented method. Why is this?

public class SettingsActivity extends Activity implements SharedPreferences.
OnSharedPreferenceChangeListener{

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

        // Display the fragment as the main content.
        getFragmentManager().beginTransaction()
                .replace(android.R.id.content, new SettingsFragment( this ))
                .commit();

        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences
( this );
        sp.registerOnSharedPreferenceChangeListener( this );

    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences 
sharedPreferences, String key) {
        if ( key.equals( "pref_catalogEdition" ) ) {
            ProgressBar bar = ( ProgressBar ) findViewById( 
R.id.catalogLoadProgressBar 
);
            bar.setVisibility(View.VISIBLE ); // WORKS!
        }
    }
}


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to