目前,我正在爲幾個不同的類實現一個名爲RowType的接口,讓我們假設類A,B和C.如何遍歷Firebase以獲取每個不同的對象?使用與Firebase的接口
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
RowType rowType = snapshot.getValue(RowType.class);
Log.d("awdjk", "qwjel");
}
我會假設,因爲插在火力地堡的所有對象要麼是A級,B,或C,我可以使用ROWTYPE來獲取快照值。但是,我收到一條錯誤消息,指出「在類RowType上找不到要序列化的屬性」。
UPDATE
接口
public interface RowType {
int EXERCISE_ROW = 0;
int REST_ROW = 1;
int SUPERSET_ROW = 2;
int PYRAMIDSET_ROW = 3;
int BUTTON_ROW = 4;
}
運動類
public class ExerciseModel implements RowType {
public String exercise, sets, reps, view, minutes, seconds, time, weight, childCount;
private EditText weightEditText, setsEditText, repsEditText;
private AutoCompleteTextView exerciseEditText;
private ImageView dragHandle;
private ExerciseRowTextWatcher exerciseRowTextWatcher;
public ExerciseRowTextWatcher getExerciseRowTextWatcher(){
return exerciseRowTextWatcher;
}
public void setExerciseRowTextWatcher(ExerciseRowTextWatcher exerciseRowTextWatcher){
this.exerciseRowTextWatcher = exerciseRowTextWatcher;
}
public ImageView getDragHandle(){
return dragHandle;
}
public void setDragHandle(ImageView dragHandle){
this.dragHandle = dragHandle;
}
public AutoCompleteTextView getExerciseEditText(){
return exerciseEditText;
}
public void setExerciseEditText(AutoCompleteTextView exerciseEditText){
this.exerciseEditText = exerciseEditText;
}
public EditText getWeightEditText(){
return weightEditText;
}
public void setWeightEditText(EditText weightEditText){
this.weightEditText = weightEditText;
}
public EditText getSetsEditText(){
return setsEditText;
}
public void setSetsEditText(EditText setsEditText){
this.setsEditText = setsEditText;
}
public EditText getRepsEditText(){
return repsEditText;
}
public void setRepsEditText(EditText repsEditText){
this.repsEditText = repsEditText;
}
public String getChildCount(){
return childCount;
}
public void setChildCount(String childCount){
this.childCount = childCount;
}
public String getExercise(){
return exercise;
}
public String getWeight(){
return weight;
}
public String getSets(){
return sets;
}
public String getReps(){
return reps;
}
public String getView(){
return view;
}
public String getMinutes(){
return minutes;
}
public String getSeconds(){
return seconds;
}
public String getTime(){ return time;}
public void setExercise(String exercise){
this.exercise = exercise;
}
public void setTime(String time){ this.time = time; }
public void setWeight(String weight){
this.weight = weight;
}
public void setMinutes(String minutes){
this.minutes = minutes;
}
public void setSeconds(String seconds){
this.seconds = seconds;
}
public void setSets(String sets){
this.sets = sets;
}
public void setView(String view){
this.view = view;
}
public void setReps(String reps){
this.reps = reps;
}
}
我有在接口實現其他類,但要保持這一簡短,我只增加鍛鍊班。其他班級比較相似。
看看這個線程https://stackoverflow.com/questions/37743661/firebase-no-properties-to-serialize-found-on-class –
請添加您的類/接口代碼。 –
@AlexMamo我更新了我的代碼 –