user701735
user701735

Reputation: 145

Retrieve checked radio button data and send to the another activity when button is pressed

I have a question: I have two radio buttons as Imagebutton and one button.

When I click on Imagebutton one I want to read that value and send it to other activity, when I press the button how can I do ?

Please provide piece of code if possible

Upvotes: 0

Views: 2113

Answers (1)

Dharmendra
Dharmendra

Reputation: 33996

package com.httpconnection;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import org.apache.http.util.ByteArrayBuffer;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class httpconnectionActivity extends Activity implements OnCheckedChangeListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout layout = new LinearLayout(this);
        layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

        RadioButton rd1 = new RadioButton(this);
        rd1.setId(1);
        rd1.setOnCheckedChangeListener(this);  
        layout.addView(rd1);
        RadioButton rd2 = new RadioButton(this);
        rd2.setId(2);
        rd2.setOnCheckedChangeListener(this); 
        layout.addView(rd2);
        setContentView(layout);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

        Intent intent = new Intent(this, xyz.class);
        intent.putExtra("MyKey", buttonView.getId());
        startActivity(intent);


    }
}

Upvotes: 1

Related Questions