亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Android Studio 3.4 中將字符串值從一個 Activity 發送到另一個

在 Android Studio 3.4 中將字符串值從一個 Activity 發送到另一個

哈士奇WWW 2023-07-13 13:53:16
請設計一個android應用程序,我想將(5)字符串值從一個活動發送到另一個活動以在不同的TextView中使用,我幾乎嘗試了我可以在網上找到的有關該主題的所有代碼,但我一直只得到一個值(我在 putExtra() 中發送的最后一個值)。我是 Android Studio 的新手,非常感謝您的每一個幫助。我已經使用 putExtra() 將一個數據發送到另一個活動,并且它工作得很好,在嘗試對多個數據執行相同操作時,我總是只收到發送的數據之一。我還嘗試使用捆綁對象來接收來自其他(接收)活動的數據。我希望在另一個活動中獲取所有這些數據(intent.putExtra("surname", "Jerry"). intent.putExtra("middlename", "chris").intent.putExtra("lastname", "Enema")),但我一直只得到“灌腸”這是我的代碼;//在第一個Activity中     send.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                String sFirstname = firstname.getText().toString();                String sLastname = lastname.getText().toString();                Intent intent = new Intent(MainActivity.this, ReceiveActivity.class);                intent.putExtra("surname" ,sFirstname);                intent.putExtra("lastname", sLastname);                startActivity(intent);            }        });//And In the second Activity名字 = findViewById(R.id.名字); 姓氏 = findViewById(R.id.firstname);Intent intent = getIntent();Bundle bundle = getIntent().getExtras();String ssurname = bundle.getString("surname");String slastname = bundle.getString("lastname");firstname.setText(ssurname);lastname.setText(slastname);
查看完整描述

2 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

嘗試這個。在第一個活動中:


String sFirstname = "Tope";

String sLastname = "Adebodun";


Intent theIntent = new Intent(MainActivity.this, ReceivingActivity.class);

theIntent.putExtra("firstname", sFirstname);

theIntent.putExtra("lastname", sLastname);

然后在第二個活動中,在 onCreate 方法中執行以下操作:


Intent intent = getIntent();

String thefirst = (String) intent.getExtras.getString("firstname");

String thelast = (String) intent.getExtras.getString("lastname");


查看完整回答
反對 回復 2023-07-13
?
UYOU

TA貢獻1878條經驗 獲得超4個贊

我不想使用getExtras所以你應該有兩個getExtra 像這樣的:


 Intent intent = getIntent();


 String ssurname = intent.getExtra("surname");

 String slastname = intent.getExtra("lastname");


 firstname.setText(ssurname);

 lastname.setText(slastname);


查看完整回答
反對 回復 2023-07-13
  • 2 回答
  • 0 關注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號