2017-05-29 176 views
0

嘗試在我的應用程序中創建設置屏幕時出現Error inflating class DropDownPreference。我在我的操作欄中添加了一個按鈕,我想啓動包含設置片段的設置活動,設置爲like this二進制XML文件行#13:錯誤膨脹類DropDownPreference

所以,我有我的SettingsActivity:

public class SettingsActivity extends Activity { 
    @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()) 
       .commit(); 
    } 

    public static class SettingsFragment extends PreferenceFragment { 

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

      // Load the preferences from an XML resource 
      addPreferencesFromResource(R.xml.preferences); 
     } 

    } 
} 

,問題中的XML:

<?xml version="1.0" encoding="utf-8"?> 

<PreferenceScreen 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:title="@string/pref_title" 
android:layout_height="match_parent" 
android:layout_width="match_parent"> 

<PreferenceCategory 
    android:key="pref_video" 
    android:title="@string/pref_video_title"> 

    <DropDownPreference 
     android:key="pref_video_quality" 
     android:title="@string/pref_video_quality" 
     android:summary="@string/pref_summary_video_quality" 
     android:entries="@array/pref_entries_video_quality" 
     android:entryValues="@array/pref_entries_video_quality" /> 

</PreferenceCategory> 

</PreferenceScreen> 

我從摸索,這個錯誤通常指向某事的代碼錯在別處知道,但我我真的不確定我的錯誤可能在哪裏。這是我的MainActivity代碼是應該推出SettingsActivity:

@Override 
public boolean onCreateOptionsMenu(Menu menu){ 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.menu, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item){ 
    switch (item.getItemId()) { 
     case R.id.preferences: 
      // Code to show SettingsActivity 
      Intent intent = new Intent(this, SettingsActivity.class); 
      startActivity(intent); 
      break; 
     default: 
      break; 
    } 

    return true; 
} 

感謝所有幫助

回答

0

解決了這個。事實證明,DropDownPreference畢竟是造成這個問題。我還沒有更多地瞭解它,但我用CheckBoxPreference取代了DropDownPreference,它工作正常。

相關問題