Ich versuche, die Daten in das RV zu füllen. Wenn ich es mit einem benutzerdefinierten Adapter (traditioneller Adapter für RV) mache. Die Daten werden aufgefüllt. Aber ich möchte die FirebaseRecyclerAdapter
verwenden. Damit kann ich etwas vom Boiler-Plate-Code reduzieren. während der Implementierung bekomme ich Failed to bounce to type
Fehler.Daten werden nicht mit FirebaseRecyclerAdapter geladen?
JSON Von Firebase
{
"subscriptions" : {
"[email protected],com" : {
"-KDnfjROKeFAL9wccsxY" : {
"category" : "Mobility",
"goal" : "afternoon body weight workout",
"length" : 1,
"title" : "Afternoon HiiT",
"weeks" : {
"week1" : [ "High Knees", "Squats", "Lunges", "Diamond Push-ups", "Lying Triceps Lifts" ]
}
}
}
}
}
Program.java
public class Program {
private String title;
private String goal;
private String category;
private int length;
HashMap<String, ArrayList<String>> weeks;
public Program() {
}
public Program(String title, String goal, String category, int length, HashMap<String, ArrayList<String>> weeks) {
this.title = title;
this.goal = goal;
this.category = category;
this.length = length;
this.weeks = weeks;
}
public String getTitle() {
return title;
}
public String getGoal() {
return goal;
}
public String getCategory() {
return category;
}
public int getLength() {
return length;
}
public HashMap<String, ArrayList<String>> getweeks() {
return weeks;
}
}
Fragment-Code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_latest, container, false);
mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mAdapter = new FirebaseRecyclerAdapter<Program, ProgramVH>(Program.class, R.layout.program_item, ProgramVH.class, mRef) {
@Override
public void populateViewHolder(final ProgramVH programViewHolder, Program mProgram, int position) {
programViewHolder.setName(program.getTitle());
programViewHolder.level.setText(program.getLength());
}
};
mRecyclerView.setAdapter(mAdapter);
FetchData();
return v;
}
public void FetchData(){
mRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
for (DataSnapshot programSnapshot : userSnapshot.getChildren()) {
program = programSnapshot.getValue(Program.class);
Log.e("VH", program.getTitle()); // Title is getting printed
}
}
}
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
@Override
public void onDestroyView() {
super.onDestroyView();
mAdapter.cleanup();
}
ViewHolder
public static class ProgramVH extends RecyclerView.ViewHolder {
protected ImageView header;
protected TextView title;
protected TextView level;
public ProgramVH(View view) {
super(view);
this.header = (ImageView) view.findViewById(R.id.coverImage);
this.title = (TextView) view.findViewById(R.id.title);
this.level = (TextView) view.findViewById(R.id.level);
}
public void setName(String name) {
title.setText(name);
}
}
STACK TRACE
08: 55: 19,045 5717-5717/com.android.sam E/VH: Nachmittag Hiit 03-30 August: 55: 19,045 5717 -5717/com.android.sam D/AndroidRuntime: Ausschalten VM03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: FATALE AUSNAHME: Haupt 03-30 08: 55: 19.045 5717- 5717/com.android.sam E/AndroidRuntime: FATALE AUSNAHME: Haupt 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime : Prozess: com.android.sam, PID: 5717 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: com.firebase.client.FirebaseException: konnte nicht auf Typ 03 - springen 30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: um com.firebase.client.DataSnapshot.getValue (DataSnapshot.java:185) 03-30 08: 55: 19.045 5717-5717/com .android.sam E/AndroidRuntime: bei com.firebase.ui.FirebaseRecyclerAdapter.parseSnapshot (FirebaseRecyclerAdapter.java:161) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: at com. Firebase.UI.FirebaseRecyclerAdapter.getItem (FirebaseRecyclerAdapter.java:150) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: um com.firebase.ui.FirebaseRecyclerAdapter.onBindViewHolder (FirebaseRecyclerAdapter.java : 190) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/An droidRuntime: bei android.support.v7.widget.RecyclerView $ Adapter.onBindViewHolder (RecyclerView.java:5465) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support. v7.widget.RecyclerView $ Adapter.bindViewHolder (RecyclerView.java:5498) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.v7.widget.RecyclerView $ Recycler .getViewForPosition (RecyclerView.java:4735) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition (RecyclerView.java: 4611) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.v7.widget.LinearLayoutManager $ LayoutState.next (LinearLayoutManager.java:1988) 03-30 08 : 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.v7.widget.LinearLayou tManager.layoutChunk (LinearLayoutManager.java:1384) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1347) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.v7.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:574) 03-30 08:55: 19.045 5717-5717/com.android.sam E/Android Runtime: bei android.support.v7.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:3026) AUGUST 03-30: 55: 19,045 5717-5717/com.android.sam E/Android Runtime: bei android.support .v7.widget.RecyclerView.dispatchLayout (RecyclerView.java:2903) August 03-30: 55: 19,045 5717-5717/com.android.sam E/Android Runtime: bei android.support.v7.widget.RecyclerView.onLayout (RecyclerView.java:3277) 03-30 08: 55: 19,045 5717-5717/com.android.sam E/Android Runtime: bei android.view.View.layout (View.java:15686) 30.03 08.55 : 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.ViewGroup.layout (ViewGroup.java:5039) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.design.widget.CoordinatorLayout.layoutChild (KoordinatorLayout.java:1087) 03-30 08: 55: 19.045 5717-5717/com .android.sam E/AndroidRuntime: bei android.support.design.widget.CoordinatorLayout.onLayoutChild (KoordinatorLayout.java:797) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: um android.support.design.widget.ViewOffsetBehavior.layoutChild (ViewOffsetBehavior.java:63) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.design.widget.HeaderScrollingViewBehavior .layoutChild (HeaderScrollingViewBehavior.java:126) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.design.widget.ViewOffsetBehavior.onLayoutChild (ViewOffsetBehavior.java:42) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.design.widget.AppBarLayout $ ScrollingViewBehavior.onLayoutChild (AppBarLayout.java:1139) 03-30 08:55 : 19.045 5717-5717/com.android.sam E/AndroidRu ntime: at android.support.design.widget.CoordinatorLayout.onLayout (KoordinatorLayout.java:810) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.View. Layout (View.java:15686) August 03-30: 55: 19,045 5.717-5.717/com.android.sam E/Android Runtime: bei android.view.ViewGroup.layout (ViewGroup.java:5039) 03-30 August : 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.v4.view.ViewPager.onLayout (ViewPager.java:1684) 03-30 08: 55: 19.045 5717-5717/com .android.sam E/AndroidRuntime: bei android.view.View.layout (View.java:15686) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view. ViewGroup.layout (ViewGroup.java:5039) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.design.widget.HeaderScrollingViewBehavior.la youtChild (HeaderScrollingViewBehavior.java:122) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.design.widget.ViewOffsetBehavior.onLayoutChild (ViewOffsetBehavior.java:42) 03-30 08: 55: 19,045 5717-5717/com.android.sam E/Android Runtime: bei android.support.design.widget.AppBarLayout $ ScrollingViewBehavior.onLayoutChild (AppBarLayout.java:1139) 30.03 8.55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.design.widget.CoordinatorLayout.onLayout (KoordinatorLayout.java:810) 03-30 08: 55: 19.045 5717-5717/com.android. sam E/AndroidRuntime: bei android.view.View.layout (View.java:15686) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.ViewGroup.layout (ViewGroup.java:5039) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/Androi dRuntime: bei android.widget.FrameLayout.layoutChildren (FrameLayout.java:579) August 03-30: 55: 19,045 5717-5717/com.android.sam E/Android Runtime: bei android.widget.FrameLayout.onLayout (FrameLayout. java: 514) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.View.layout (View.java:15686) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.ViewGroup.layout (ViewGroup.java:5039) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.widget.RelativeLayout.onLayout (RelativeLayout.java:1077) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.View.layout (View.java: 15686) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.ViewGroup.layout (ViewGroup.Java: 5039) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.support.v4.widget.DrawerLayout.onLayout (DrawerLayout.java:1183) 03-30 08 : 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.View.layout (View.java:15686) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.ViewGroup.layout (ViewGroup.java:5039) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.widget.FrameLayout.layoutChildren (FrameLayout.java:579) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.widget.FrameLayout.onLayout (FrameLayout.java:514) 03-30 08:55 : 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.view.View.layout (View.java:15686) 03-30 08: 55: 19.045 5717-5717/com.a ndroid.sam E/AndroidRuntime: bei android.view.ViewGroup.layout (ViewGroup.java:5039) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.widget.LinearLayout .setChildFrame (LinearLayout.java:1703) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.widget.LinearLayout.layoutVertical (LinearLayout.java:1557) 03-30 08: 55: 19.045 5717-5717/com.android.sam E/AndroidRuntime: bei android.widget.LinearLayout.onLayout (LinearLayout.java:1466) 03-30 08: 55: 19.045 5717-5717/com.android. sam E/Android Runtime: bei android.view.View
UPDATE
Die Daten gefüllt wird immer, wenn ich die folgenden ref
Firebase mRef = new Firebase("https://arulnadhan.firebaseio.com/").child("subscriptions/[email protected],com");
verwenden, aber es funktioniert nicht, wenn ich die unten verwenden ref
& der FetchData() Methode!
Firebase mRef = new Firebase("https://arulnadhan.firebaseio.com/subscriptions");
public void FetchData(){
mRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
for (DataSnapshot programSnapshot : userSnapshot.getChildren()) {
program = programSnapshot.getValue(Program.class);
Log.e("VH", program.getTitle()); // Title is getting printed
}
}
}
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
** JSON unter Abonnements Knoten **
{
"[email protected],com" : {
"-KDnhRwHjssOejrqyenP" : {
"category" : "Strength",
"goal" : "This workout can be done while on the phone!",
"length" : 1,
"title" : "Hello Workouts",
"weeks" : {
"week1" : [ "High Knees", "Jumping Jacks", "Wall sit", "Pushups", "Sit-ups", "Step ups", "Squats", "Tricep dips on chair", "Plank", "High Knees running in place", "Lunges", "Pushup and rotation", "Side plank (alternate per round)", "Alternating Push-Up Plank", "Chest Expander", "Diamond Push-ups", "Dive Bomber Push-ups", "Butt Kickers", "Lying Triceps Lifts", "One Arm Side Push-up", "Overhead Arm Clap", "Overhead Press", "Power Circles", "Push-up and Rotation", "T Push-ups", "Reverse Plank", "Spiderman Push-up", "T Raise", "Tricep Dips", "Wall Push-ups", "Wide Arm Push-ups", "Burpees" ]
}
},
"-KDni3TN4NMyGXePyp92" : {
"category" : "Strength",
"goal" : "This workout can be done by a BABUJI",
"length" : 1,
"title" : "Indian Workouts",
"weeks" : {
"week1" : [ "Diamond Pushups", "Jackknives", "Plyo Lunges", "Plyo Squats", "Single leg plank (alternate per round)", "Plyo Lunges", "Pushup and rotation", "Weighted side plank (alternate per round)", "Alternating Push-Up Plank", "Chest Expander", "Diamond Push-ups", "Dive Bomber Push-ups", "One Arm Side Push-up", "Overhead Press", "Push-up and Rotation", "T Push-ups", "Spiderman Push-up", "Wide Arm Push-ups", "Burpee Pushups" ]
}
}
},
"[email protected],com" : {
"-KDnfjROKeFAL9wccsxY" : {
"category" : "Mobility",
"goal" : "afternoon body weight workout",
"length" : 1,
"title" : "Afternoon HiiT",
"weeks" : {
"week1" : [ "High Knees", "Squats", "Lunges", "Diamond Push-ups", "Lying Triceps Lifts" ]
}
},
"-KDps90Dn6XtJc6Co00b" : {
"category" : "Strength",
"goal" : "goal",
"length" : 1,
"title" : "title",
"weeks" : {
"week1" : [ "Diamond Pushups", "Jackknives", "Plyo Lunges", "Plyo Squats", "Single leg plank (alternate per round)", "Plyo Lunges", "Pushup and rotation", "Weighted side plank (alternate per round)", "Alternating Push-Up Plank", "Chest Expander", "Diamond Push-ups", "Dive Bomber Push-ups", "One Arm Side Push-up", "Overhead Press", "Push-up and Rotation", "T Push-ups", "Spiderman Push-up", "Wide Arm Push-ups", "Burpee Pushups" ]
}
}
}
}
Warum rufst du 'mRef.addListenerForSingleValueEvent()' * innen * 'populateViewHolder()'? Das ergibt für mich keinen Sinn. Ich empfehle dringend, dass Sie ein paar Schritte zurück und * zuerst * folgen Sie dem [FirebaseUI Codelab] (https://github.com/firebase/FirebaseUI-Android/tree/master/codelabs/chat). –
Ich habe das chatMessage-Beispiel verfolgt. Aber nachdem ich diese Antwort gesehen habe, habe ich sie in 'populateViewHolder()' http://stackoverflow.com/a/34561726/2781359 – user3467240
geändert. Jeder Benutzer unter 'https: // arulnadan.firebaseio.com /' hat Abonnements. Der Root-Knoten selbst hat keine Abonnements. Sie können eine Ebene in einer Abfrage nicht überspringen. Wenn Sie eine Liste aller Abonnements für alle Benutzer anzeigen möchten, benötigen Sie eine Liste aller Abonnements in der Datenbank. –