Note that there are some explanatory texts on larger screens.

plurals
  1. POFeedback Activity - boolean bRequiresResponse = responseCheckbox.isChecked(); - how do i change this boolean to a string using an if statement?
    text
    copied!<p>E.g. </p> <pre><code>if boolean = true string = "A response is required". if boolean = false string = "No response is required". </code></pre> <p>This is because, when the email is sent, i want to include this string in the email message.I have checked the internet but what i have found doesn't suit my code.</p> <p>Here is the Java code:</p> <pre><code>package com.android.motivateme3; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Spinner; import android.support.v4.app.NavUtils; public class Feedback extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_feedback); // Show the Up button in the action bar. setupActionBar(); } public void sendFeedback(View button) { // Do click handling here final EditText nameField = (EditText) findViewById(R.id.EditTextName); String name = nameField.getText().toString(); final EditText emailField = (EditText) findViewById(R.id.EditTextEmail); String email = emailField.getText().toString(); final EditText feedbackField = (EditText) findViewById(R.id.EditTextFeedbackBody); String feedback = feedbackField.getText().toString(); final Spinner feedbackSpinner = (Spinner) findViewById(R.id.SpinnerFeedbackType); String feedbackType = feedbackSpinner.getSelectedItem().toString(); final CheckBox responseCheckbox = (CheckBox) findViewById(R.id.CheckBoxResponse); boolean bRequiresResponse = responseCheckbox.isChecked(); Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Motivate Me Feedback "+"("+feedbackType+")"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "parekhmihir98@gmail.com"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, feedback+"(From "+name+","+email+")"+bRequiresResponse); startActivity(Intent.createChooser(emailIntent, "Send email via:"));} /** * Set up the {@link android.app.ActionBar}. */ private void setupActionBar() { getActionBar().setDisplayHomeAsUpEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.feedback, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } </code></pre> <p>}</p> <p>XML code:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Feedback" &gt; &lt;TextView android:id="@+id/TextViewTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/feedbacktitle" android:textSize="10pt"&gt; &lt;/TextView&gt; &lt;CheckBox android:id="@+id/CheckBoxResponse" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/EditTextFeedbackBody" android:layout_below="@+id/EditTextFeedbackBody" android:text="@string/feedbackresponse" /&gt; &lt;Button android:id="@+id/ButtonSendFeedback" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/CheckBoxResponse" android:layout_below="@+id/CheckBoxResponse" android:onClick="sendFeedback" android:text="@string/feedbackbutton" /&gt; &lt;EditText android:id="@+id/EditTextEmail" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/SpinnerFeedbackType" android:layout_below="@+id/TextViewTitle" android:layout_marginTop="32dp" android:ems="10" android:hint="@string/feedbackemail" android:inputType="textEmailAddress" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;EditText android:id="@+id/EditTextName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/TextViewTitle" android:layout_below="@+id/TextViewTitle" android:ems="10" android:hint="@string/feedbackname" android:inputType="textPersonName" /&gt; &lt;Spinner android:id="@+id/SpinnerFeedbackType" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/EditTextName" android:layout_below="@+id/EditTextEmail" android:entries="@array/feedbacktypelist" android:prompt="@string/feedbacktype1" /&gt; &lt;EditText android:id="@+id/EditTextFeedbackBody" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/SpinnerFeedbackType" android:layout_centerVertical="true" android:ems="10" android:hint="@string/feedbackbody" android:inputType="textMultiLine" android:lines="5" /&gt; &lt;/RelativeLayout&gt; </code></pre>
 

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