4

Can I include a preference in Layout like how we include a layout in another layout using <include layout=""/> tag.

My layout code goes like this

<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>

in the above layout i am trying to include preference @xml/set_variables but my application will crash if i uncomment <include layout="@xml/set_variables"/> . Please can any one suggest is there any way to include preference in layout or just I should forget this .

Sharanabasu Angadi
  • 4,304
  • 8
  • 43
  • 67

1 Answers1

2

I gone through this Link and found solution In onCreate of PreferenceActivity I have added

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

and added ListView in settings layout

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

it met my requirement

Community
  • 1
  • 1
Sharanabasu Angadi
  • 4,304
  • 8
  • 43
  • 67