android - RecyclerView not generating list when it has a view above it -


so cannot make recyclerview generate given list once have view above it. view above , recycler view both within linearlayout , single child of nestedscrollview (used collapsing toolbar). once recyclerview view in fragment works expected.

stockscompletelistfragment.java

public class stockscompletelistfragment extends fragment {      @nullable     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         nestedscrollview sv = (nestedscrollview) inflater.inflate(                 r.layout.fragment_stocks_completelist, container, false);         linearlayout mylinear = (linearlayout) sv.findviewbyid(r.id.mainlinear);         recyclerview rv = (recyclerview) mylinear.findviewbyid(r.id.recyclerview);         if (rv == null){             toast.maketext(getactivity(),"null", toast.length_short).show();         }         setuprecyclerview(rv);         return sv;     }      private void setuprecyclerview(recyclerview recyclerview) {         recyclerview.setlayoutmanager(new linearlayoutmanager(recyclerview.getcontext()));         recyclerview.setadapter(new simplestringrecyclerviewadapter(getactivity(),                 getrandomsublist(cheeses.scheesestrings, 30)));     }      private list<string> getrandomsublist(string[] array, int amount) {         arraylist<string> list = new arraylist<>(amount);         random random = new random();         while (list.size() < amount) {             list.add(array[random.nextint(array.length)]);         }         return list;     }      public static class simplestringrecyclerviewadapter             extends recyclerview.adapter<simplestringrecyclerviewadapter.viewholder> {          private final typedvalue mtypedvalue = new typedvalue();         private int mbackground;         private list<string> mvalues;          public static class viewholder extends recyclerview.viewholder {             public string mboundstring;              public final view mview;             public final imageview mimageview;             public final textview mtextview;              public viewholder(view view) {                 super(view);                 mview = view;                 mimageview = (imageview) view.findviewbyid(r.id.avatar);                 mtextview = (textview) view.findviewbyid(android.r.id.text1);             }              @override             public string tostring() {                 return super.tostring() + " '" + mtextview.gettext();             }         }          public string getvalueat(int position) {             return mvalues.get(position);         }          public simplestringrecyclerviewadapter(context context, list<string> items) {             context.gettheme().resolveattribute(r.attr.selectableitembackground, mtypedvalue, true);             mbackground = mtypedvalue.resourceid;             mvalues = items;         }          @override         public viewholder oncreateviewholder(viewgroup parent, int viewtype) {             view view = layoutinflater.from(parent.getcontext())                     .inflate(r.layout.list_item, parent, false);             view.setbackgroundresource(mbackground);             return new viewholder(view);         }          @override         public void onbindviewholder(final viewholder holder, int position) {             holder.mboundstring = mvalues.get(position);             holder.mtextview.settext(mvalues.get(position));              holder.mview.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     context context = v.getcontext();                     intent intent = new intent(context, cheesedetailactivity.class);                     intent.putextra(cheesedetailactivity.extra_name, holder.mboundstring);                      context.startactivity(intent);                 }             });              glide.with(holder.mimageview.getcontext())                     .load(cheeses.getrandomcheesedrawable())                     .fitcenter()                     .into(holder.mimageview);         }          @override         public int getitemcount() {             return mvalues.size();         }     } } 

and here's layout xml fragment_stocks_completelist.xml:

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.nestedscrollview     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     app:layout_behavior="@string/appbar_scrolling_view_behavior">      <linearlayout         android:id="@+id/mainlinear"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical">          <linearlayout             android:id="@+id/progressbarlayout"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="center_vertical"             android:layout_marginbottom="4dp"             android:layout_margintop="8dp"             android:background="@color/graybackground"             android:gravity="center_vertical|center_horizontal"             android:padding="4dp"             android:visibility="gone">              <progressbar                 android:id="@+id/progressbar1"                 style="?android:attr/progressbarstyle"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content" />          </linearlayout>          <android.support.v7.widget.recyclerview             android:id="@+id/recyclerview"             android:layout_width="match_parent"             android:layout_height="wrap_content" />      </linearlayout>  </android.support.v4.widget.nestedscrollview> 

you need set

    android:fillviewport="true" 

on nestedrecyclerview. if put coordinatorlayout specify behavior (which you've done)


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -