You can define a custom preference. The process goes something like this:
In your XML declare the root view as id:widget_frame and declare the text views as title and summary. Then, add the other elements you'd like to use in the layout - in your case the toggle button.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/widget_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@android:id/title"
style="@android:style/TextAppearance.DeviceDefault.SearchResult.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:id="@android:id/summary"
style="@android:style/TextAppearance.DeviceDefault.SearchResult.Subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Summary" />
<Switch
android:id="@+id/switch"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Then, in a class that derives from Preference, override the onCreateView method:
SwitchPreference.java
@Override
protected View onCreateView( ViewGroup parent )
{
LayoutInflater li = (LayoutInflater)getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
return li.inflate( R.layout.seekbar_preference, parent, false);
}
Then, in preferences.xml, use the preference:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<com.example.SwitchPreference
android:key="pref_max_volume"
android:title="@string/max_volume" />
<com.example.SwitchPreference
android:key="pref_balance"
android:title="@string/balance" />
</PreferenceScreen>
Since Switch inherits from CompoundButton, you can implement the OnCheckedChangeListener to define the behavior when the switch is changed from on to off or vice-versa. And you can define onClickListener for the preference itself and make it open the second preference screen.
You may have to edit some of the code, as I've just written it here without checking it, but this is the basic concept. This is the original answer I used to adjust the code for you.
EDIT: Add answer to question in comments.
You can do something like this to implement the custom behavior when you click on the preference
SwitchPreference custom_preference = findPreference("preference_id");
custom_preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
//implement your custom behavior here
}
});