2012-12-28 11 views
5

otrzymuję następujący błąd podczas przełączania z xml do GUI dla pliku arkusza preferencje:błąd Eclipse Android podczas przełączania do GUI xml

Wyjątek generowany podczas renderowania: com.android.layoutlib.bridge.MockView nie mogą być oddane do android.view.ViewGroup szczegóły Wyjątkiem są rejestrowane w oknie> Pokaż widok> Error Log Poniższe klasy nie można znaleźć: - PreferenceCategory (Fix Build Path, Edycja XML) - PreferenceScreen (Fix Build Path, Edycja XML)

Mój plik xml wygląda następująco:

<?xml version="1.0" encoding="UTF-8"?> 
<PreferenceScreen 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <PreferenceCategory 
    android:title="Activation"> 
    <CheckBoxPreference 
     android:title="Title1" 
     android:defaultValue="false" 
     android:key="checkbox1"> 
    </CheckBoxPreference> 
    </PreferenceCategory> 

    <PreferenceCategory 
    android:title="Option1"> 
    <PreferenceScreen 
     android:title="Set Option"> 
    <CheckBoxPreference 
     android:title="ENABLE OPTION" 
     android:defaultValue="false" 
     android:summary="text" 
     android:key="checkboxOption1"> 
    </CheckBoxPreference> 
    <CheckBoxPreference 
     android:title="DISPLAY OPTIONS" 
     android:defaultValue="false" 
     android:summary="text" 
     android:key="checkboxDisplay1"> 
    </CheckBoxPreference> 
    <EditTextPreference 
     android:title="OPTION2" 
     android:name="Option2" 
     android:summary="text" 
     android:defaultValue="1" 
     android:key="editOption2"> 
    </EditTextPreference> 
    <CheckBoxPreference 
     android:title="OPTION3" 
     android:defaultValue="false" 
     android:summary="text" 
     android:key="checkboxOption3"> 
    </CheckBoxPreference> 
    </PreferenceScreen> 
    </PreferenceCategory> 

    <PreferenceCategory 
    android:title="Option4"> 
    <PreferenceScreen 
     android:title="Set Option4"> 
    <CheckBoxPreference 
     android:title="OPTION4" 
     android:defaultValue="false" 
     android:summary="" 
     android:key="checkboxOption4"> 
    </CheckBoxPreference> 
    <CheckBoxPreference 
     android:title="OPTION5" 
     android:defaultValue="false" 
     android:summary="text" 
     android:key="checkboxOption5"> 
    </CheckBoxPreference> 
    <EditTextPreference 
     android:title="OPTION6" 
     android:name="Option6" 
     android:summary="text" 
     android:defaultValue="1" 
     android:key="editOption6"> 
    </EditTextPreference> 
    <EditTextPreference 
     android:title="OPTION7" 
     android:name="Option7" 
     android:summary="text" 
     android:defaultValue="1" 
     android:key="editOption7"> 
    </EditTextPreference> 
    <EditTextPreference 
     android:title="OPTION8" 
     android:name="Option8" 
     android:summary="text" 
     android:defaultValue="1" 
     android:key="editOption8"> 
    </EditTextPreference> 
    </PreferenceScreen> 
    </PreferenceCategory> 

    <PreferenceCategory 
    android:title="OPTION9"> 
    <PreferenceScreen 
     android:title="Option9"> 
    <EditTextPreference 
     android:title="Option9" 
     android:name="Option9" 
     android:summary="text" 
     android:defaultValue="" 
     android:key="editOption9"> 
    </EditTextPreference> 
    </PreferenceScreen>  
    </PreferenceCategory> 

</PreferenceScreen> 

Każda pomoc będzie bardzo mile widziane

+0

Mam dokładnie ten sam problem. –

Odpowiedz

4

miałem ten problem, bo traktuje listę preferencji jak normalnej aktywności. W rzeczywistości jest zupełnie inaczej. Najpierw musisz przenieść plik XML z res/layout na res/xml (w Eclipse musisz ręcznie utworzyć ten folder). Można również użyć innego kodu Java:

import android.os.Bundle; 
import android.preference.PreferenceActivity; 

public class Settings extends PreferenceActivity { //NOT activity! 

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

     // Initialize the preference screen defined in /res/xml/preference.xml 
     addPreferencesFromResource(R.xml.preferences); //NOT setContentView 
    } 

} 

Dostaniesz ostrzeżenie dla poziomu API> = 11 o addPreferencesFromResource wycofywana. To dlatego, że Android chce, abyś przełączył się na ekran preferencji oparty na fragmentach ("PreferenceFragments"), co jest nieco bardziej skomplikowane. Oto przykład: here.

+0

Dzięki 1 "Czy to sprawdzić! Pozdrawiam – ctaylor

Powiązane problemy