Can I inflate PreferenceScreen inside an alert dialog?
This is what I’ve tried:
final LayoutInflater factory = LayoutInflater.from(this);
final View myDialog = factory.inflate(R.xml.prefScr, null);
final Dialog dialog = new AlertDialog.Builder(this)
.setTitle("This is Dialog")
.setView(myDialog)
.create();
this gives me exception:
android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
I don’t think it is possible to use a
PreferenceScreenoutside of aPreferenceActivitylike this…but here are a few alternatives:1) Make the
Activityappear as a dialog by using a style in yourManifest:2) Use an
AlertDialogas you currently are but inflate it with your own custom layout that has the same features as youPreferenceScreendoes. Then you would have to manage the getting and setting of preferences manually.3) Just use a
PreferenceActivitywith its ownPreferenceDialog. This might not really be the same thing that you want, but using aPreferenceActivitywill save you a lot of the work of manually handling all of your preferences.