I'm testing the app in the new Android N Preview version and I'm having one problem with the preference activity (in MarshMallow - Android 6.0 and lower versions is working fine).
I'm using: 'com.android.support:appcompat-v7:22.2.1' 'com.android.support:design:22.2.1'
This is the error:
java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.widget.LinearLayout
at com.myApp.PreferenceActivity.setUpNestedScreen(PreferenceActivity.java:1606)
at com.myApp.PreferenceActivity.onPreferenceTreeClick(PreferenceActivity.java:1594)
at android.preference.Preference.performClick(Preference.java:1005)
at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:214)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1155)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3087)
at android.widget.AbsListView$3.run(AbsListView.java:4002)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:6066)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:770)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:660)
This is the code that is pointing the error:
public void setUpNestedScreen(PreferenceScreen preferenceScreen) {
final Dialog dialog = preferenceScreen.getDialog();
Toolbar bar;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent(); //Here is the line 1606
View topView = LayoutInflater.from(this).inflate(R.layout.preference_toolbar, root, false);
root.addView(topView, 0); // insert at top
bar = (Toolbar) topView.findViewById(R.id.toolbar);
bar.setTitle(preferenceScreen.getTitle());
bar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
}