【问题标题】:How to parcel cascading classes with Parceler?如何使用 Parceler 打包级联类?
【发布时间】:2016-04-28 17:38:29
【问题描述】:

我可以像这样使用 Parceler 打包一些模型:

@Parcel(Serialization.BEAN)
public class PasswordSetModel {

    private String mPassword;
    private String mRepetition;

    /* Getter & Setter */
    ...

但如果这个类是另一个类的一部分,则该机制不起作用。我正在为 mPasswordSetModel 获取 NPE。在构造函数中创建实例不起作用,因为成员 mPassword 和 mRepetition 在解包后为空。

@Parcel
public class RegistrationModel {

    private PasswordSetModel mPasswordSetModel;

    /* Getter & Setter */
    ...

那么我怎样才能使用 Parceler 进行打包呢?

【问题讨论】:

    标签: parceler


    【解决方案1】:

    好的,问题是我使用了“错误的”setter 方法。为了使用流畅的界面风格,我这样做了:

    public String getPassword() {
        return mPassword;
    }
    
    public PasswordSetModel setPassword(String password) {
        mPassword = password;
        return this;
    }
    
    public String getRepetition() {
        return mRepetition;
    }
    
    public PasswordSetModel setRepetition(String repetition) {
        mRepetition = repetition;
        return this;
    }
    

    现在似乎找到了 setter,因此模型为 NULL

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多