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 9110801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:21:19+00:00 2026-06-17T03:21:19+00:00

I am creating an android application in which i have a activity which contain

  • 0

I am creating an android application in which i have a activity which contain several elements like Switch, TextView etc.

I need to get the values from all Switch elements whether it is checked or not.

it will be great if anyone show me the proper way to transfer multiple values to different activity for further calculation.

Thanks

here is my XML code:

           <LinearLayout
                android:id="@+id/configSwitchHldr"
                android:layout_marginTop="10dp"
                android:layout_span="2"
                android:gravity="center"
                android:orientation="vertical"
                android:paddingLeft="30dp"
                android:paddingRight="30dp" >

                <TextView 
                    android:text="@string/coreHardware"
                    android:layout_width="fill_parent"
                    android:layout_height="20dp"
                    android:textColor="@color/green"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    />
                <View 
                   android:layout_width="fill_parent"
                   android:layout_height="2dp"       
                   android:background="#363636" />
                <Switch
                    android:id="@+id/switch1"
                    android:layout_width="fill_parent"
                    android:layout_height="14.5sp"
                    android:textOn="ON"
                    android:textOff="OFF"
                    android:text="CPU"              
                    android:paddingLeft="5dp"
                    android:paddingRight="5dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    />
                <View 
                   android:layout_width="fill_parent"
                   android:layout_height="1dp"       
                   android:background="#363636" />

                <Switch
                    android:id="@+id/switch2"
                    android:layout_width="fill_parent"
                    android:layout_height="14.5sp"
                    android:textOn="ON"
                    android:textOff="OFF"
                    android:text="Memory" 
                    android:paddingLeft="5dp"
                    android:paddingRight="5dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"/>

                <View 
                   android:layout_width="fill_parent"
                   android:layout_height="1dp"       
                   android:background="#363636" />

                <Switch
                    android:id="@+id/switch3"
                    android:layout_width="fill_parent"
                    android:layout_height="14.5sp"
                    android:textOn="ON"
                    android:textOff="OFF"
                    android:text="Storage" 
                    android:paddingLeft="5dp"
                    android:paddingRight="5dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"/>

                <View 
                   android:layout_width="fill_parent"
                   android:layout_height="1dp"       
                   android:background="#363636" />

            </LinearLayout>
  • 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-17T03:21:20+00:00Added an answer on June 17, 2026 at 3:21 am

    Ok, so based on your comment this is how it could be done:

    In your first Activity, you would need a method, that gathers all the switches states and pass them along to the next activity. Passing parameters along to other Activities can be achieved by putting them inside the Intent you send to open the new Activity.

    The method for getting the Switches states and passing them to a new Activity would roughly look something like this:

    Intent i = new Intent(MainActivity.this, NewActivity.class);
    i.putExtra("switch1", switch1.isChecked());
    i.putExtra("switch2", switch2.isChecked());
    i.putExtra("switch3", switch3.isChecked());
    startActivity(i);
    

    Put this inside the onClickListener for a Button for instance like so:

    button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, NewActivity.class);
            i.putExtra("switch1", switch1.isChecked());
            i.putExtra("switch2", switch2.isChecked());
            i.putExtra("switch3", switch3.isChecked());
            startActivity(i);
        }
    });
    

    Now when you click the Button you’ll be sent to NewActivity.

    To retrieve the parameters passed on from the MainActivity, you should do something like this in you onCreate method of the NewActivity:

    boolean bool1 = getIntent().getExtras().getBoolean("switch1");
    boolean bool2 = getIntent().getExtras().getBoolean("switch2");
    boolean bool3 = getIntent().getExtras().getBoolean("switch3");
    

    You could pass the variables on from MainActivity by putting them inside a boolean array, but that is overkill in my opinion.

    Also take a look at this SO post: How do I pass data between Activities in Android application? – there’s a lot of these.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For the Android application I am currently creating I would like to have a
I am creating a application for android, in one of the activity i have
I am creating an Android application which will have some embedded music inside of
I am creating an android application in which I have to insert an image
I need an advice. I am creating an android application that have multiple List
I'm creating a Android application which uses a Switch . I'm trying to listen
I am creating one android application which will have API to create a new
When creating an Android application using Loaders, should every activity and fragment have its
I'm creating an android application in which i will need to store data using
I am creating one android test application , in which i have one button.

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.