zoukankan      html  css  js  c++  java
  • Why do I want to avoid nondefault constructors in fragments?

    Make a bundle object and insert your data (in this example your Category object). Be careful, you can't pass this object directly into the bundle, unless it's serializable. I think it's better to build your object in the fragment, and put only an id or something else into bundle. This is the code to create and attach a bundle:

    Bundle args =newBundle();
    args.putLong("key", value);
    yourFragment.setArguments(args);

    After that, in your fragment access data:

    Type value = getArguments().getType("key");

    That's all.

    reference link:http://stackoverflow.com/questions/12062946/why-do-i-want-to-avoid-non-default-constructors-in-fragments

  • 相关阅读:
    抽象工厂模式
    外观模式
    策略模式
    状态模式
    观察者模式
    装饰者模式
    模板方法模式
    适配器模式
    中介者模式
    组合模式
  • 原文地址:https://www.cnblogs.com/savagemorgan/p/2908784.html
Copyright © 2011-2022 走看看