How to show the indeterminate progress icon in a custom PreferenceActivity?
public class MyPreferences extends Pr开发者_高级运维eferenceActivity {
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
...
setProgressBarIndeterminateVisibility(true);
setProgressBarVisibility(true);
}
}
At the first requestWindowFeature() call, this throws:
ERROR/AndroidRuntime(16406): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
Clearly I've not added any content at this point. Has the PreferenceActivity changed some state during the super.onCreate() which causes any children to think it has? Or is there some manifest attribute I should be using?
I should also point out I'm creating these Preferences without xml, i.e. entirely programmatically, but the code snippet is enough to show the problem appears to arise in either case.
The issue is that you have super.onCreate() before requestWindowFeature(). Since this is a PreferenceActivity, there are some standard items on the screen that are created in onCreate().
Simply move onCreate() below requestWindowFeature().
精彩评论