• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to get Radio button value?

dhritirao

Lurker
Jun 24, 2010
2
0
Hi buddies,

Actualy i'm working with radio buttons in android,

what i want to do is when i click the radio button the value of the radio button has to diaplay in editbox .I don't know where i'm going wrong,please
anybody help me regarding this.And one more thing is that i'm unable to do this in TableLayout format ,i want to display UI look like this, first radio button and editbox in one row and other radio button and editbox in second row ...

Thank you,

This is my main.xml file


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:eek:rientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<RadioGroup
android:id="@+id/rg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:eek:rientation="vertical"
>
<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="+"
></RadioButton>
<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="-"
></RadioButton>

</RadioGroup>
<EditText
android:id="@+id/etext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></EditText>
<EditText
android:id="@+id/etext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" ></EditText>

</LinearLayout>


And my java file

package com.android.app11;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class App11 extends Activity {
RadioButton rb1;
RadioButton rb2;
RadioGroup rg;
EditText text1;
EditText text2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
rg=(RadioGroup)findViewById(R.id.rg);
rb1=(RadioButton)findViewById(R.id.rb1);
rb2=(RadioButton)findViewById(R.id.rb2);
text1=(EditText)findViewById(R.id.etext1);
text2=(EditText)findViewById(R.id.etext2);


if(rb1.isChecked()==true)

{ text1.setText(rb1.getText());}

if(rb2.isChecked()==true)

{ text2.setText(rb2.getText());}

}

}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones