PopulateViewHolder no se ejecuta con FirebaseRecyclerAdapter (Android)

Estoy intentando utilizar un FirebaseRecyclerAdapter para poblar un RecyclerView en un fragmento, con datos de mi base de datos de Firebase.

Mi principal problema es que el método populateViewHolder nunca se llama, por lo que no aparece nada en el RecyclerView .

Seguí los pasos de la documentación de la Firebase UI :

Https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md

Las reglas de mi base de datos Firebase:

 { "rules": { ".read": "true", ".write": "true" } } 

En mi gradle , he añadido esta dependencia:

 compile 'com.firebaseui:firebase-ui-database:0.4.1' 

Aquí está el método onCreateView en mi fragmento:

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_dev_list, container, false); Log.d("ROOT_VIEW", rootView.toString()); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); Log.d("RECYCLER_VIEW", mRecyclerView.toString()); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); Log.d("ITEM_RECYCLER", Integer.toString(mRecyclerView.getLayoutManager().getItemCount())); DatabaseReference devs = FirebaseDatabase.getInstance().getReference().child("users").child("devs"); FirebaseRecyclerAdapter<Developer, DeveloperViewHolder> adapter = new FirebaseRecyclerAdapter<Developer, DeveloperViewHolder>( Developer.class, R.layout.dev_list_row, DeveloperViewHolder.class, devs ) { @Override protected void populateViewHolder(DeveloperViewHolder viewHolder, Developer developer, int position) { Log.d("ON CREATE VIEW", "before"); viewHolder.setFirstName(developer.getFirstN()); viewHolder.setLastName(developer.getLastN()); viewHolder.setAddress(developer.getAddress()); Log.d("ON CREATE VIEW", "populate"); } }; Log.d("COUNT_ADAPTER", Integer.toString(adapter.getItemCount())); Log.d("ADAPTER", adapter.toString()); Log.d("RECYCLER VIEW", mRecyclerView.toString()); mRecyclerView.setAdapter(adapter); Log.d("ON CREATE VIEW", "end"); return rootView; } 

Y aquí está mi clase DeveloperViewHolder :

 public static class DeveloperViewHolder extends RecyclerView.ViewHolder { TextView firstName; TextView lastName; TextView address; View mView; public DeveloperViewHolder(View v) { super(v); this.mView = v; } public void setFirstName(String firstN) { this.firstName = (TextView) mView.findViewById(R.id.firstname_row); this.firstName.setText(firstN); } public void setLastName(String lastN) { this.lastName = (TextView) mView.findViewById(R.id.lastname_row); this.lastName.setText(lastN); } public void setAddress(String addr) { this.address = (TextView) mView.findViewById(R.id.address_row); this.address.setText(addr); } } 

La clase Developer (clase de modelo):

 public class Developer { private String firstN; private String lastN; private String email; private String address; public Developer() { } public Developer(String firstN, String lastN, String email, String address) { this.firstN = firstN; this.lastN = lastN; this.email = email; this.address = address; } public String getFirstN() { return firstN; } public void setFirstN(String firstN) { this.firstN = firstN; } public String getLastN() { return lastN; } public void setLastN(String lastN) { this.lastN = lastN; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } } 

Y finalmente, algunos registros :

 [ 07-08 09:42:42.773 18621:18668 D/ ] HostConnection::get() New Host Connection established 0x7f938cdb65c0, tid 18668 I/OpenGLRenderer: Initialized EGL, version 1.4 D/OpenGLRenderer: Enabling debug mode 0 I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead. I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead. I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead. D/ACTION BAR?: android.support.v7.app.ToolbarActionBar@23efcd8a D/ROOT_VIEW: android.widget.LinearLayout{27403c65 VE.... ......I. 0,0-0,0} D/RECYCLER_VIEW: android.support.v7.widget.RecyclerView{23dead3a VFED.V.. ......I. 0,0-0,0 #7f0e00e5 app:id/recycler_view} D/ITEM_RECYCLER: 0 I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:2 and remote module com.google.android.gms.firebase_database:2 I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 2 D/COUNT_ADAPTER: 0 D/ADAPTER: raphaelgrau.example.com.tabsapp.fragment.tabs.DevListFragment$1@29ec2dc7 D/RECYCLER VIEW: android.support.v7.widget.RecyclerView{23dead3a VFED.V.. ......I. 0,0-0,0 #7f0e00e5 app:id/recycler_view} D/ON CREATE VIEW: end E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/raphaelgrau.example.com.tabsapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]] background_crash E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.crash.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/raphaelgrau.example.com.tabsapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]] background_crash W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources. background_crash W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources. background_crash W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources. background_crash W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources. background_crash D/ChimeraCfgMgr: Reading stored module config background_crash I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:2 background_crash I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 2 background_crash D/ChimeraFileApk: Primary ABI of requesting process is x86_64 background_crash I/art: DexFile_isDexOptNeeded failed to open oat file '/data/dalvik-cache/x86_64/data@data@com.google.android.gms@app_chimera@m@00000002@DynamiteModulesC_GmsCore_prodlmp_alldpi_release.apk@classes.dex' for file location '/data/data/com.google.android.gms/app_chimera/m/00000002/DynamiteModulesC_GmsCore_prodlmp_alldpi_release.apk': Failed to open oat filename for reading: No such file or directory background_crash D/ChimeraFileApk: Classloading successful. Optimized code found. background_crash I/FirebaseCrashReceiverServiceImpl: FirebaseCrashReceiverServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000002/DynamiteModulesC_GmsCore_prodlmp_alldpi_release.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]] background_crash D/FirebaseCrashReceiverServiceImpl: onCreate background_crash I/DynamiteModule: Considering local module com.google.android.gms.flags:0 and remote module com.google.android.gms.flags:1 background_crash I/DynamiteModule: Selected remote version of com.google.android.gms.flags, version >= 1 background_crash I/FirebaseCrashSenderServiceImpl: FirebaseCrashSenderServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000002/DynamiteModulesC_GmsCore_prodlmp_alldpi_release.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]] background_crash D/FirebaseCrashSenderServiceImpl: onCreate 

One Solution collect form web for “PopulateViewHolder no se ejecuta con FirebaseRecyclerAdapter (Android)”

He arreglado mi problema gracias a este documento:

https://codelabs.developers.google.com/codelabs/firebase-android/#6

Necesitaba agregar un RecyclerView.AdapterDataObserver() :

 mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { super.onItemRangeInserted(positionStart, itemCount); int friendlyMessageCount = mFirebaseAdapter.getItemCount(); int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition(); // If the recycler view is initially being loaded or the // user is at the bottom of the list, scroll to the bottom // of the list to show the newly added message. if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) { mMessageRecyclerView.scrollToPosition(positionStart); } } }); 

¡Problema resuelto!

  • ItemDecoration sobreescribir getItemOffsets () y animación
  • Android: ¿cómo puedo insertar un RecyclerView dentro de CardView?
  • Facebook Anuncios nativos en RycyclerView android
  • ¿Hay observadores escritos en RecyclerView.Adapter para saber si el conjunto de datos ha sido cambiado?
  • Error al inflar la clase RecyclerView
  • Android Recyclerview GridLayoutManager espaciamiento de columnas
  • Eliminar elementos de RecyclerView
  • Recyclerview Adaptador y Glide - misma imagen cada 4-5 filas
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.