第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何在Android中將一個值從一個活動傳遞到另一個活動?

如何在Android中將一個值從一個活動傳遞到另一個活動?

郎朗坤 2019-08-03 03:03:57
如何在Android中將一個值從一個活動傳遞到另一個活動?我用AutuCompleteTextView[ACTV]和按鈕創(chuàng)建了一個活動。我在ACTV中輸入一些文本,然后按下按鈕。按下按鈕后,我希望活動轉(zhuǎn)到另一個活動。在第二個活動中,我只想將在ACTV(第一個Actvity)中輸入的文本顯示為TextView。我知道如何開始第二項活動,具體如下:Intent i = new Intent(this, ActivityTwo.class);startActivity(i);我對此進行了編碼,以獲得從ACTV輸入的文本。AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);CharSequence getrec=textView.getText();這里的問題是如何將“getrec”(在我按下按鈕后)從第一個活動傳遞到第二個活動。后來在第二次活動中收到了“getrec”。請假定我已經(jīng)使用“onClick(Viewv)”為按鈕創(chuàng)建了事件處理程序類。
查看完整描述

3 回答

?
慕俠2389804

TA貢獻1719條經(jīng)驗 獲得超6個贊

您可以在Android中使用Bundle進行同樣的操作。

創(chuàng)建意圖:

Intent i = new Intent(this, ActivityTwo.class);AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);String getrec=textView.getText().toString();//Create the bundleBundle bundle = new Bundle();//Add your data to bundlebundle.putString(“stuff”, getrec);//Add the bundle to the intenti.putExtras(bundle);//Fire that second activitystartActivity(i);

現(xiàn)在,在第二個活動中,從包中檢索數(shù)據(jù):

//Get the bundleBundle bundle = getIntent().getExtras();//Extract the data…String stuff = bundle.getString(“stuff”);




查看完整回答
反對 回復(fù) 2019-08-04
?
慕碼人8056858

TA貢獻1803條經(jīng)驗 獲得超6個贊

將數(shù)據(jù)從一項活動傳遞到另一項活動的標(biāo)準(zhǔn)方法:

如果要將大量數(shù)據(jù)從一個活動發(fā)送到另一個活動,則可以將數(shù)據(jù)放入一個包中,然后使用putExtra()方法。

//Create the `intent`
 Intent i = new Intent(this, ActivityTwo.class);String one="xxxxxxxxxxxxxxx";String two="xxxxxxxxxxxxxxxxxxxxx";//Create the bundleBundle bundle = new Bundle();//Add your data to bundlebundle.putString(“ONE”, one);bundle.putString(“TWO”, two);  //Add the bundle to the intenti.putExtras(bundle);//Fire that second activitystartActivity(i);

否則您可以使用putExtra()直接發(fā)送數(shù)據(jù)和getExtra()來獲取數(shù)據(jù)。

Intent i=new Intent(this, ActivityTwo.class);i.putExtra("One",one);i.putExtra("Two",two);startActivity(i);




查看完整回答
反對 回復(fù) 2019-08-04
?
鴻蒙傳說

TA貢獻1865條經(jīng)驗 獲得超7個贊


以這種方式實施

String i="hi";Intent i = new Intent(this, ActivityTwo.class);//Create the bundleBundle b = new Bundle();//Add your data to bundleb.putString(“stuff”, i);i.putExtras(b);startActivity(i);

開始那第二次activity,在這里面class若要使用綁定值,請使用以下代碼

Bundle bundle = getIntent().getExtras();String text= bundle.getString("stuff");




查看完整回答
反對 回復(fù) 2019-08-04
  • 3 回答
  • 0 關(guān)注
  • 974 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號