gpt4 book ai didi

variables - 将变量从一项事件发送到另一项事件

转载 作者:行者123 更新时间:2023-12-01 02:34:16 25 4
gpt4 key购买 nike

我有一个屏幕,我在其中存储电话号码,然后转到另一个屏幕并启动事件的主要部分,在那里我发送文本消息,我试图获取我在第一个事件中输入的号码。我有发送消息的所有代码,但它不会从以前的事件中获取号码。这是我的第一个事件的代码:

public class StoreNumberActivity extends Host_Setting_PageActivity {
/** Called when the activity is first created. */
@Override


public void onCreate(Bundle savedInstanceState) {
super.on``Create(savedInstanceState);
setContentView(R.layout.notificationsettings);

final EditText editText= (EditText) findViewById(R.id.HostPhoneNumber);

//Juston class to schedule edit
Button Save = (Button) findViewById(R.id.SaveBtn);
Save.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(StoreNumberActivity.this, "Number was Saved Successfully", Toast.LENGTH_LONG).show();

}
});
Button Send = (Button) findViewById(R.id.SendBtn);
Send.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String Number = editText.getText().toString();
Intent myIntent = new Intent(StoreNumberActivity.this, Host_Setting_PageActivity.class);
myIntent.putExtra("Phone Num", Number);
startActivity(myIntent);
}


and my code from the second activity:



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


/** setting the view of the activity to xml */
setContentView(R.layout.messageme);
final Bundle bundle = getIntent().getExtras();

final EditText editText= (EditText) findViewById(R.id.yourname);
final EditText phonenumber= (EditText) findViewById(R.id.phone);
final EditText emailaddress= (EditText) findViewById(R.id.email);
final EditText messagebox= (EditText) findViewById(R.id.messages);
final EditText number = (EditText) findViewById(R.id.HostPhoneNumber);

button= (Button) findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = getIntent(); // this is just for example purpose
myIntent.getStringExtra("PhoneNum");
String Number = bundle.getString("Phone Num");
String Name = editText.getText().toString();
String Phone = phonenumber.getText().toString();
String Email = emailaddress.getText().toString();
String Message = messagebox.getText().toString();



sendSMS(Number, "Name: " + Name + "\n" + "\n" + "Email: " + Email + "\n" + "\n" + "Phone: " + Phone + "\n" + "\n" + Message);
}

最佳答案

以下是一些 StackOverflow 答案,它们可能会满足您的需求:

pass value between activity android

How do I pass data between activities in Android?

关于variables - 将变量从一项事件发送到另一项事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11037643/

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