Note that there are some explanatory texts on larger screens.

plurals
  1. POSending radio button data to next activity
    primarykey
    data
    text
    <p>I'm trying to allow the user to enter their Name, and click on one of three radio buttons, and click on a submit button. And on the next activity, it will display their name and the radio button they selected. I've managed to be able to send the name, but I'm not sure how to send the radio button selection. Can someone help?</p> <p>This is what I have in the main activity layout .xml</p> <pre><code>&lt;EditText android:id="@+id/operatorName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="25dp" android:ems="10" android:hint="@string/operator_name" /&gt; &lt;RadioGroup android:id="@+id/radioShifts" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginTop="10dp" &gt; &lt;RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/radio1" android:checked="true" android:onClick="onRadioButtonClicked" /&gt; &lt;RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/radio2" android:onClick="onRadioButtonClicked" /&gt; &lt;RadioButton android:id="@+id/radioButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/radio3" android:onClick="onRadioButtonClicked" /&gt; &lt;/RadioGroup&gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="28dp" android:text="@string/button1" android:onClick="onButton1" /&gt; </code></pre> <p>And I have this in the main_activity .java file:</p> <pre><code> public final static String OP_NAME = "com.cyapps.downtimer.OPNAME"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onRadioButtonClicked(View view) { // Is the button now checked? boolean checked = ((RadioButton) view).isChecked(); // Check which radio button was clicked switch(view.getId()) { case R.id.radioButton1: if (checked) break; case R.id.radioButton2: if (checked) break; case R.id.radioButton3: if (checked) break; } /* Intent intent = new Intent(this, WinderDTActivity.class); EditText button = (EditText) findViewById(RadioGroup.getCheckedRadioButtonId()); String radioChosen = button.getText().toString(); intent.putExtra(RADIO_CHOSEN, radioChosen);*/ } public void onButton1(View view) { Intent intent = new Intent(this, WinderDTActivity.class); EditText editText = (EditText) findViewById(R.id.operatorName); String opName = editText.getText().toString(); intent.putExtra(OP_NAME, opName); startActivity(intent); } </code></pre> <p>The code in /* */ is what I think I should do.. But I'm not sure. Someone help please? I'll really appreciate it..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload