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

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

Android:如何將Parcelable對象傳遞給Intent并使用bundle

Android:如何將Parcelable對象傳遞給Intent并使用bundle

慕俠2389804 2019-12-03 09:55:55
為什么捆綁有g(shù)etParcelableArrayList,getParcelable方法;但是 Intent只有putParcelableArrayListExtra方法嗎?我只能傳送object<T>,不能傳送ArrayList一個元素嗎?那是getParcelable為了什么
查看完整描述

3 回答

?
隔江千里

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

Intent提供了一堆重載的putExtra()方法。


假設(shè)您有一個Foo類正確地實現(xiàn)了Parcelable,將其放入Activity中的Intent中:


Intent intent = new Intent(getBaseContext(), NextActivity.class);

Foo foo = new Foo();

intent.putExtra("foo ", foo);

startActivity(intent);

要從其他活動中獲取它:


Foo foo = getIntent().getExtras().getParcelable("foo");

希望這可以幫助。


查看完整回答
反對 回復 2019-12-03
?
富國滬深

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

重要的是要記住,您的模型必須實現(xiàn)Parcelable接口和靜態(tài)CREATOR方法。這種情況是列表


 private static final String MODEL_LIST = "MODEL_LIST";

    public MainFragment() {}


    public static MainFragment newInstance(ArrayList<YourModel>   

models) {

        MainFragment fragment = new MainFragment();

        Bundle args = new Bundle();

        args.putParcelableArrayList(MODEL_LIST,models);

        fragment.setArguments(args);

        return fragment;

    }


    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        if (getArguments() != null) {

            ArrayList<YourModel> models = getArguments().getParcelableArrayList(MODEL_LIST);

        }

    }


查看完整回答
反對 回復 2019-12-03
?
小怪獸愛吃肉

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

首先使用給定技術(shù)創(chuàng)建Parcelable,然后


public static CreditCardDetail newInstance(CreditCardItemBO creditCardItem) {

        CreditCardDetail fragment = new CreditCardDetail();

        Bundle args = new Bundle();

        args.putParcelable(CREDIT_KEY,creditCardItem);

        fragment.setArguments(args);

        return fragment;

    }

并得到像


 if(getArguments() != null)

 {

    creditCardItem = getArguments().getParcelable(CREDIT_KEY);               

 }

哪里


public static final String CREDIT_KEY = "creditKey";


查看完整回答
反對 回復 2019-12-03
  • 3 回答
  • 0 關(guān)注
  • 810 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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