I have two layouts one for before API level-14 and the other is for what's after. I need to use toggle button in before level-14 API and a switch button for the one after level-14.
The problem is that I want to use both with the same id in R.id.button1 or Do I have to make each one with a different id and check inside the Java code the version of API running so I find the view by id that works for the API. And if so how can I do that please provide a sample of code. Thanks for your time.
These are the XML files
layout-v14:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Switch
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp" />
</RelativeLayout>
Ordinary layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ToggleButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp" />
</RelativeLayout>
The Java code
CompoundButton button = (CompoundButton) findViewById(R.id.button1);