Soy nuevo en android y quiero que me ayuden a asignar el texto a los radiobutton
que están contenidos en un RadioGroup
, gracias.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="@+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RadioGroup>
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
RadioGroup radioGroup;
RadioButton radioButton1;
RadioButton radioButton2;
RadioButton radioButton3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
radioButton1 = (RadioButton) findViewById(R.id.radio1);
radioButton2 = (RadioButton) findViewById(R.id.radio2);
radioButton3 = (RadioButton) findViewById(R.id.radio3);
//Asignar Texto de cada RadioButton ?
radioButton1.setText( "ONE");
radioButton2.setText("TWO");
radioButton3.setText("THREE");
}
}