0

例如

if boolean = true
 string = "A response is required".
 if boolean = false
 string = "No response is required". 

这是因为,当发送电子邮件时,我想在电子邮件中包含这个字符串。我已经检查了互联网,但我发现的内容不适合我的代码。

这是Java代码:

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);
}

}

XML 代码:

<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" >

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

<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" />

<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" />

<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" >

<requestFocus />
</EditText>

<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" />

<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" />

<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" />

</RelativeLayout>
4

0 回答 0