-1

I am trying to have the user fill out a form then those fields auto-populate into an email. I was able to convert the EditText to strings as well as the spinner, but I am confused as to how to do it with RadioGroup. I want the text from the button which is selected to appear in the email. I know that getText won't work, but what will. Thank you

JAVA

    //This happens when you press the submit button at the bottom of the form.
    public void submit(View button) {
    // Do click handling here
    //What happens here is the input from each field is taken in and converted into
    //Strings and placed into their correct variables.

    final EditText FirstNameField = (EditText) findViewById(R.id.EditTextFirstName);
    fName = FirstNameField.getText().toString();

    final EditText LastNameField = (EditText) findViewById(R.id.EditTextLastName);
    lName = LastNameField.getText().toString();

    final EditText emailField = (EditText) findViewById(R.id.EditTextEmail);
    email = emailField.getText().toString();

    final EditText feedbackField = (EditText) findViewById(R.id.EditTextFeedbackBody);
    feedback = feedbackField.getText().toString();

    final Spinner feedbackSpinner = (Spinner) findViewById(R.id.SpinnerFeedbackType);
    feedbackType = feedbackSpinner.getSelectedItem().toString();

    final RadioGroup ApproveorReject = (RadioGroup) findViewById(R.id.radiochoice);
    fAnswer = ApproveorReject.getText().toString();


    //calls the sendEmail() from below to pull up a list of apps installed
    //on the phone that can handle emailing.
    sendEmail();
}


//This bit of code pulls up a list of apps that can handle emailing.
private void sendEmail() {

    //When the user chooses an app of the list that pops up, these lines below
    //will auto-populate the fields of the email with the input from above.
    //The user can take one last look at the email before hitting that send button
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{"recipient@example.com"});
    i.putExtra(Intent.EXTRA_SUBJECT, feedbackType);
    i.putExtra(Intent.EXTRA_TEXT, lName + ", " + fName + "\n" + email + "\n" + feedback + fAnswer );
    startActivity(Intent.createChooser(i, "Send mail..."));


}

}

XML

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<RelativeLayout
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/TextViewTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="@string/feedbacktitle"
        android:textSize="10pt">
    </TextView>

    <!--First Name-->
    <EditText
        android:id="@+id/EditTextFirstName"
        android:layout_height="wrap_content"
        android:hint="@string/feedbackfirst"
        android:inputType="textPersonName"
        android:layout_width="fill_parent"
        android:layout_below="@+id/TextViewTitle">
    </EditText>

    <!--Last Name-->
    <EditText
        android:id="@+id/EditTextLastName"
        android:layout_height="wrap_content"
        android:hint="@string/feedbacklast"
        android:inputType="textPersonName"
        android:layout_width="fill_parent"
        android:layout_below="@id/EditTextFirstName">
    </EditText>

    <!-- Email -->
    <EditText
        android:id="@+id/EditTextEmail"
        android:layout_height="wrap_content"
        android:hint="@string/feedbackemail"
        android:inputType="textEmailAddress"
        android:layout_width="fill_parent"
        android:layout_below="@id/EditTextLastName">
    </EditText>

    <Spinner
        android:id="@+id/SpinnerFeedbackType"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:entries="@array/Types_of_Errors"
        android:layout_below="@+id/EditTextEmail">
    </Spinner>

    <EditText
        android:id="@+id/EditTextFeedbackBody"
        android:layout_height="wrap_content"
        android:hint="@string/feedbackbody"
        android:inputType="textMultiLine"
        android:lines="5"
        android:layout_width="fill_parent"
        android:layout_below="@+id/SpinnerFeedbackType">

    </EditText>

    <RadioGroup
        android:id="@+id/radiochoice"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/EditTextFeedbackBody"
        android:orientation="horizontal">

        <RadioButton
        android:id="@+id/AcceptRadio"
        android:layout_width="wrap_content"
        android:layout_marginStart="50dp"
        android:layout_height="wrap_content"
        android:text="@string/acceptbutton" />

        <RadioButton
            android:id="@+id/RejectRadio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/rejectbutton"
            android:layout_marginStart="115dp" />
    </RadioGroup>

    <EditText
        android:id="@+id/RejectResponse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/rejectreason"
        android:layout_marginTop="410dp"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="20dp"
        android:inputType="text"/>

    <Button
        android:id="@+id/ButtonSend"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/sendform"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="590dp"
        android:onClick="submit"/>

</RelativeLayout>

Steve Irwin
  • 5
  • 1
  • 3
  • refer this: http://stackoverflow.com/questions/6440259/how-to-get-the-selected-index-of-a-radiogroup-in-android – Calvin Oct 15 '15 at 13:20

2 Answers2

0

Try this

RadioButton btn=(RadioButton)findViewById(ApproveorReject.getCheckedRadioButtonId());
String selectedText=btn.getText().toString();
Ravi
  • 34,851
  • 21
  • 122
  • 183
0

Try

 ApproveorReject.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
    public void onCheckedChanged(RadioGroup group, int checkedId) {

        RadioButton rb=(RadioButton)findViewById(checkedId);
        String param = rb.getText();
    }
});
nuridin selimko
  • 332
  • 1
  • 11