android - FirebaseRecyclerAdapter with multiple ViewType ==> Blank screen? -


i'm using firebaserecycleradapter multiple viewtype in current project shows black screen!!?

can me resolve this??

does problem in code or layout ?? or thing else

the problem firebaserecycleradapter found way written can never support multiple view types. true ?

my java code:

private void displaychatmessages() {      recyclerview listofmessages = (recyclerview)findviewbyid(r.id.myrv);     madapter = new firebaserecycleradapter<chatmessage, recyclerview.viewholder>(             chatmessage.class, r.layout.list_item_chat, recyclerview.viewholder.class, firebasedatabase.getinstance().getreference()) {         @override         protected void populateviewholder(final recyclerview.viewholder viewholder, final chatmessage user,                                           final int position) {             switch (user.getmessageuser()) {                 case "test@test.com":                     holderme vh1 = (holderme)viewholder;                     populatetype1(vh1, user, position);                     toaa1("cbn");                     break;                 case "test2@test2.com":                     populatetype2((holderyou) viewholder, user, position);                     break;                 case "3":                     populatetype3((holderdate) viewholder, user, position);                     break;             }         }          @override         public recyclerview.viewholder oncreateviewholder(viewgroup parent, int viewtype) {             switch (viewtype) {                 case 1:                     view usertype1 = layoutinflater.from(parent.getcontext())                             .inflate(r.layout.layout_holder_me, parent, false);                     toaa1("cbn2");                     return new holderme(usertype1);                 case 2:                     view usertype2 = layoutinflater.from(parent.getcontext())                             .inflate(r.layout.layout_holder_you, parent, false);                     return new holderyou(usertype2);                 case 3:                     view usertype3 = layoutinflater.from(parent.getcontext())                             .inflate(r.layout.layout_holder_date, parent, false);                     return new holderdate(usertype3);             }             return super.oncreateviewholder(parent, viewtype);         }          @override         public int getitemviewtype(int position) {             chatmessage user = getitem(position);             switch (user.getmessageuser()) {                 case "test@test.com":                     toaa1("cbn3");                     return 1;                 case "test2@test2.com":                     return 2;                 case "3":                     return 3;             }             return super.getitemviewtype(position);         }          private void populatetype1(holderme v, chatmessage model, int position) {             v.gettimeview().settext(dateformat.format("hh:mm",model.getmessagetime()));             v.gettextv().settext(model.getmessagetext());         }          private void toaa1( string text) {             toast.maketext(chatactivity.this,text,toast.length_long).show();         }         private void  populatetype2(holderyou vv, chatmessage model, int position) {             vv.gettextv().settext(dateformat.format("hh:mm",model.getmessagetime()));             vv.gettimeview().settext(model.getmessagetext());         }         private void populatetype3(holderdate vcv, chatmessage model, int position) {             vcv.getdate().settext(dateformat.format("hh:mm",model.getmessagetime()));         }     };     listofmessages.setadapter(madapter); } 

my xml:

xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     app:layout_behavior="@string/appbar_scrolling_view_behavior"     tools:context="com.marxhack.ma153.activitychatnew"     tools:showin="@layout/app_bar_activity_chat_new">      <edittext         android:id="@+id/msginput"         android:layout_width="310dp"         android:layout_height="35dp"         android:layout_marginbottom="8dp"         android:layout_marginleft="8dp"         android:layout_marginright="8dp"         android:layout_margintop="8dp"         android:ems="10"         android:inputtype="textpersonname"         app:layout_constraintbottom_tobottomof="parent"         app:layout_constrainthorizontal_bias="0.17"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_torightof="parent"         app:layout_constrainttop_totopof="parent"         app:layout_constraintvertical_bias="0.982"         android:layout_marginstart="8dp"         android:layout_marginend="8dp" />      <android.support.v7.widget.recyclerview         android:id="@+id/myrv"         android:layout_width="358dp"         android:layout_height="450dp"         android:layout_marginbottom="8dp"         android:layout_marginleft="8dp"         android:layout_marginright="8dp"         android:layout_margintop="8dp"         app:layout_constraintbottom_tobottomof="parent"         app:layout_constraintleft_toleftof="parent"         app:layout_constraintright_torightof="parent"         app:layout_constrainttop_totopof="parent"         app:layout_constraintvertical_bias="0.0" /> </android.support.constraint.constraintlayout> 

edit : problem solved

    .     .     . recyclerview recycler = (recyclerview)findviewbyid(r.id.myrv);         recycler.sethasfixedsize(true);         recycler.setlayoutmanager(new linearlayoutmanager(this));     .     .     . 

i working yesterday, , remember layout field variable, seems me must true then. upon closer inspection can see final, can change once initiated.

enter image description here

something take in mind here firebase-ui libraries, of them, meant speed starting project. after while or while dealing more complex cases, have take care of it.

in case, if take @ library classes see bigger advantage switch case use handle child event listener updating data. check out, , maybe pull request can all, luck friend :)


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -