问题描述:

I have class called "someThing". I need to save this class to Firebase not as "something", but as "some_thing". I can save it with HashMap, but it is not clear to me, how to get values back (mainly for adapter).

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;

}

}

Converting data to hash map for saving:

public Map<String, Object> toMap() {

HashMap<String, Object> result = new HashMap<>();

result.put("some_thing", something_value);

return result;

}

But how to load them back into adapter? Adapter is basic adapter:

public class SomethingAdapter extends ArrayAdapter<Something> {

public SomethingAdapter(Context context, int resource) {

super(context, resource);

}

}

网友答案:

You can use Firebase Annotations @PropertyName

网友答案:

Thank to Ahmed Abidi, here is solution:

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;
 }

}
相关阅读:
Top