2017-01-19 32 views
1

我有一个叫“someThing”的课。我需要将该课程保存到Firebase,而不是“某些东西”,而是“some_thing”。我可以用HashMap保存它,但是我不清楚如何获取值(主要是用于适配器)。如何在Android Firebase数据库中为变量设置不同的名称?

public class Something { 

    private int someThing; 

    public Something(int someThing) { 
    this.someThing = someThing; 
    } 

    public int getSomeThing() { 
    return someThing; 
    } 

    public void setSomeThing(int someThing) { 
    this.someThing = someThing; 
    } 

} 

将数据转换成散列映射保存:

public Map<String, Object> toMap() { 
    HashMap<String, Object> result = new HashMap<>(); 
    result.put("some_thing", something_value); 
    return result; 
} 

但如何将它们回装入适配器?适配器是基本适配器:

public class SomethingAdapter extends ArrayAdapter<Something> { 
    public SomethingAdapter(Context context, int resource) { 
    super(context, resource); 
    } 
} 

回答

3

感谢到Ahmed Abidi,这里是解决方案:

public class Something { 

@PropertyName("some_thing") 
private int someThing; 

public Something(int someThing) { 
this.someThing = someThing; 
} 

@PropertyName("some_thing") 
public int getSomeThing() { 
return someThing; 
} 

@PropertyName("some_thing") 
public void setSomeThing(int someThing) { 
this.someThing = someThing; 
} 

} 
相关问题