Java 让它保持不变?

Java 让它保持不变?,java,android,Java,Android,我可以选择用户给我发电子邮件的地方,我只需要知道如何发邮件,这样邮件的“主题”总是固定在1美元。并将其设置为用户无法更改主题的位置 下面是我的EmailActivity.java import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Inte

我可以选择用户给我发电子邮件的地方,我只需要知道如何发邮件,这样邮件的“主题”总是固定在1美元。并将其设置为用户无法更改主题的位置

下面是我的EmailActivity.java

    import android.app.Activity;
    import android.content.ActivityNotFoundException;
    import android.content.ComponentName;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;


    public class EmailActivity extends Activity {

    Button buttonSend;
    EditText textTo;
    EditText textSubject;
    EditText textMessage;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.email_layout);

    buttonSend = (Button) findViewById(R.id.buttonSend);
    textTo = (EditText) findViewById(R.id.editTextTo);
    textSubject = (EditText) findViewById(R.id.editTextSubject);
    textMessage = (EditText) findViewById(R.id.editTextMessage);

    buttonSend.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            String to = textTo.getText().toString();
            String subject = textSubject.getText().toString();
            String message = textMessage.getText().toString();

            Intent email = new Intent(Intent.ACTION_SEND);
            email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
            //email.putExtra(Intent.EXTRA_CC, new String[]{ to});
            //email.putExtra(Intent.EXTRA_BCC, new String[]{to});
            email.putExtra(Intent.EXTRA_SUBJECT, subject);
            email.putExtra(Intent.EXTRA_TEXT, message);

            //need this to prompts email client only
            email.setType("message/rfc822");

            startActivity(Intent.createChooser(email, "Choose an Email client :"));

        }
    });
}
}

这是我的xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
    android:id="@+id/textViewPhoneNo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="To : "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/editTextTo"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress" >

    <requestFocus />

    </EditText>

    <TextView
    android:id="@+id/textViewSubject"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Subject : "
    android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
    android:id="@+id/editTextSubject"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
    </EditText>

    <TextView
    android:id="@+id/textViewMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Message : "
    android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
    android:id="@+id/editTextMessage"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="top"
    android:inputType="textMultiLine"
    android:lines="5" />

<Button
    android:id="@+id/buttonSend"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Send" />

   </LinearLayout>

既然您提到您不想让用户编辑主题,您可以继续使用
文本视图
而不是
编辑文本
。直接在那里设置主题的文本值即可

有关
TextView
s和
EditText
s的更多信息,您可以查看以下链接:


如果您不希望用户编辑文本,为什么不使用文本视图而不是EditText?然后直接在xml中将文本设置为“$1”@sept这样的小东西总是愚弄我。你是什么意思O这就是你想要的答案吗?@sept是的,伙计,每天凌晨3点都在编码,所以像这样的小东西从我身边溜走了,我明白了。可以然后继续,将其添加为答案。以便其他用户可以看到。