gpt4 book ai didi

java - 当用户输入时更新他们的输入

转载 作者:行者123 更新时间:2023-12-02 11:59:39 24 4
gpt4 key购买 nike

此问题与利用电子邮件 Intent 的基本应用程序有关。

应用程序的 UI 显示 4 个输入:

  1. 电子邮件地址
  2. 主题
  3. 姓名
  4. 消息
  5. 按钮

该消息是 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"));

}
});

}

}

谢谢,

最佳答案

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

关于java - 当用户输入时更新他们的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47357929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com