0

I have a Settings.xml layout which has buttons, textviews,etc. I am working on changing this to use PreferenceScreens for the settings layouts. I am aware that I can't use buttons like the way we use in a LinearLayout or any other. My questions are as follows:

  1. Is there a way I can use the buttons, views from my settings.xml into my Preference_settings.xml?
  2. Is there a way to make a connection between the Settings.xml and Preference_Settings.xml?

This is my settings.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:orientation="vertical"
    android:weightSum="10" >

    <RelativeLayout
        android:id="@+id/top_panel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" >

        <Button
            android:id="@+id/select_flight_button"
            android:layout_width="@dimen/settings_button_width"
            android:layout_height="wrap_content"
            android:textColor="@drawable/custom_text_color_for_buttons"
            android:textSize="@dimen/button_text_size"
            android:textStyle="bold" />      
    </RelativeLayout>


    <LinearLayout
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="bottom|center_horizontal"
        android:layout_weight="2.25"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="17dp"
        android:gravity="top|center_horizontal"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/app_version_tablet_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:background="@color/transparent"
            android:gravity="center_horizontal"
            android:src="@drawable/tablet_info" />

        <TextView
            android:id="@+id/last_outbound_sync_timestamp"
            style="@style/settings_sync_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="5dp"
            android:focusable="false"
            android:text="@string/last_sync_time_unknown" />

</LinearLayout>

This is my preference_settings.xml

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

    <PreferenceCategory
        android:title="Flight Selection" >

        <Preference
            android:title="Change Flight"
            android:selectable="true"
            android:key="@string/choose_flight"
            android:icon="@drawable/icon_select_flight" />
        <Preference
            android:title="Close Flight"
            android:selectable="true"
            android:key="@string/close_flight_successful"
            android:icon="@drawable/icon_select_flight" />

    </PreferenceCategory>

    <PreferenceCategory
        android:title="Terminal Panel" >

        <Preference
            android:title="Change Terminal"
            android:selectable="true"
            android:icon="@drawable/icon_terminal" />

    </PreferenceCategory>

    <PreferenceCategory
        android:title="Printer Panel" >

        <Preference
            android:title="Choose Printer"
            android:icon="@drawable/icon_printer" />

    </PreferenceCategory>
        <SwitchPreference
            android:title="Enable Sync" />

</PreferenceScreen>
punit1337
  • 21
  • 1
  • 10
  • Well I don't understand *exactly* what you want but if my guess is correct here then perhaps you want to include on layout in another layout. `` – Abbas Aug 30 '16 at 12:06
  • @Abbas, What I want to do is setup my layouts and its attributes in a different resource file and use them in my preferences.xml. Is that possible? – punit1337 Aug 30 '16 at 12:08

1 Answers1

0

If you want to pick individual views from a layout to add in another layout then no, you can't do that. However you can add an entire layout in another layout.

Like so in your preference_settings.xml

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

<!-- Your layout views from settings will start from top place the layout wherever you want-->
<include layout="@layout/settings" />

<PreferenceCategory
    android:title="Flight Selection" >

    <Preference
        android:title="Change Flight"
        android:selectable="true"
        android:key="@string/choose_flight"
        android:icon="@drawable/icon_select_flight" />
    <Preference
        android:title="Close Flight"
        android:selectable="true"
        android:key="@string/close_flight_successful"
        android:icon="@drawable/icon_select_flight" />

</PreferenceCategory>

<PreferenceCategory
    android:title="Terminal Panel" >

    <Preference
        android:title="Change Terminal"
        android:selectable="true"
        android:icon="@drawable/icon_terminal" />

</PreferenceCategory>

<PreferenceCategory
    android:title="Printer Panel" >

    <Preference
        android:title="Choose Printer"
        android:icon="@drawable/icon_printer" />

</PreferenceCategory>
    <SwitchPreference
        android:title="Enable Sync" />

Abbas
  • 3,529
  • 5
  • 36
  • 64