2012-08-08 82 views
1

我可以在佈局中包含偏好,例如我們如何使用<include layout=""/>標籤將佈局包含在另一個佈局中。如何在佈局中包含偏好

我的佈局代碼是這樣

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

    android:padding="@dimen/padding_medium" 
    android:text="@string/hello_world" 
    tools:context=".MainActivity" /> 

<include layout="@layout/settings"/> 
<!-- <include layout="@xml/set_variables"/> --> 
</LinearLayout> 

在上面的佈局我試圖包括偏好@xml/set_variables,但如果我取消<include layout="@xml/set_variables"/>我的應用程序會崩潰。請任何人建議有沒有辦法在佈局中包含偏好或只是我應該忘記這一點。

回答

0

我通過this Link了,發現解決方案 在PreferenceActivitonCreateŸ我已經加入

setContentView(R.layout.settings); 
addPreferencesFromResource(R.xml.set_variables); 

settings佈局添加ListView

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

它滿足了我的要求