此问题与使用电子邮件意图的基本应用有关。
应用程序的UI显示4个输入:
消息属于textMultiLine
输入类型。
该邮件的默认文字为:"Hello CustomerName (This is a dynamic variable that would update as the user types their name in input number 3), could you please review our app..."
我要做的是将CustomerName
实时更新为实际客户名称,因为他们在输入数字3
(姓名)中输入了该名称。
来源:
package com.example.apit.testemailintent;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText receiver, sub, mesg;
EditText customerName;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
receiver = (EditText) findViewById(R.id.email);
sub = (EditText) findViewById(R.id.subject);
customerName = (EditText) findViewById(R.id.name);
mesg = (EditText) findViewById(R.id.message);
btn = (Button) findViewById(R.id.submitButton);
addListenerOnButton1();
}
public void addListenerOnButton1() {
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String Sendto = receiver.getText().toString();
String subject = sub.getText().toString();
String cusName = customerName.getText().toString();
String mesgs = "Hello " + cusName + ", could you please review our app...?";
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{Sendto});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, mesgs);
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Please Choose an Email Client"));
}
});
}
}
谢谢,
答案 0 :(得分:1)
nameEditText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,int before, int count) {
messageEditText.setText("Hello " + s + " could you please review our app")
}
});