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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

請(qǐng)問如何將一些數(shù)據(jù)傳輸?shù)搅硪粋€(gè)片段?

請(qǐng)問如何將一些數(shù)據(jù)傳輸?shù)搅硪粋€(gè)片段?

如何將一些數(shù)據(jù)傳輸?shù)搅硪粋€(gè)片段?如何將一些數(shù)據(jù)傳輸?shù)搅硪粋€(gè)Fragment同樣地,它也是用extras為intents?
查看完整描述

3 回答

?
揚(yáng)帆大魚

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊

Bundle..下面是一個(gè)例子:

Fragment fragment = new Fragment();Bundle bundle = new Bundle();bundle.putInt(key, value);fragment.setArguments(bundle);

bundle為許多數(shù)據(jù)類型提供了方法??匆?/trans>這,這個(gè)

然后在你的Fragment,檢索數(shù)據(jù)(例如,在onCreate()方法)與:

Bundle bundle = this.getArguments();if (bundle != null) {
        int myInt = bundle.getInt(key, defaultValue);}



查看完整回答
反對(duì) 回復(fù) 2019-10-17
?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

為了擴(kuò)展前面的答案,就像Ankit所說的,對(duì)于復(fù)雜的對(duì)象,您需要實(shí)現(xiàn)Serialable。例如,對(duì)于簡(jiǎn)單對(duì)象:

public class MyClass implements Serializable {
    private static final long serialVersionUID = -2163051469151804394L;
    private int id;
    private String created;}

在你身上:

Bundle args = new Bundle();args.putSerializable(TAG_MY_CLASS, myClass);Fragment toFragment = new ToFragment();
toFragment.setArguments(args);getFragmentManager()
    .beginTransaction()
    .replace(R.id.body, toFragment, TAG_TO_FRAGMENT)
    .addToBackStack(TAG_TO_FRAGMENT).commit();

在你的房間里:

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

    Bundle args = getArguments();
    MyClass myClass = (MyClass) args        .getSerializable(TAG_MY_CLASS);



查看完整回答
反對(duì) 回復(fù) 2019-10-17
?
慕勒3428872

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超6個(gè)贊

使用片段到片段傳遞數(shù)據(jù)的完整代碼

Fragment fragment = new Fragment(); // replace your custom fragment class Bundle bundle = new Bundle();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                bundle.putString("key","value"); // use as per your need
                fragment.setArguments(bundle);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.replace(viewID,fragment);
                fragmentTransaction.commit();

在自定義片段類中

Bundle mBundle = new Bundle();mBundle = getArguments();mBundle.getString(key);  
// key must be same which was given in first fragment



查看完整回答
反對(duì) 回復(fù) 2019-10-17
  • 3 回答
  • 0 關(guān)注
  • 463 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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