Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:08:29+00:00 2026-06-18T11:08:29+00:00

I have two layouts one for before API level-14 and the other is for

  • 0

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:08:30+00:00Added an answer on June 18, 2026 at 11:08 am

    Both of them extends CompoundButton, so you can use the same ID, but if you want the same code, you have to limit your useness to CompoundButton class.

    Edit

    CompoundButton button = (CompoundButton) findViewById(R.id.button1);
    button.setChecked(checked);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two layouts, one is the main layout inside which I am including
I have a layout with two children one after another, like this: |<view1><text1> |
I have some DataGrids with pretty standard one-line itemrenderers, but need to use a
I have a application which use two layouts in portrait ans landscape. To load
I have an activity that has two layouts one in the folder layout and
I have some NSViews that I'm putting in one of two layouts depending on
I created one linear layout and I have added two relative layout. I wish
I have created two folders layout and layout-land with two xml files, one for
Ho I have two list view on a frame layout. I want one overlay
I have a JFrame with null layout and two one character JLabels on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.