title: Layout_behavior with an Adapter inside another one
body: <p>I have been searching and found some close questions and answer but none of them works.</p>
  
  <p>I'm using <em>CoordinatorLayout</em> for a list <em>RecyclerView</em> with <em>AppBarLayout</em> and <em>ToolBar</em>.</p>
  
  <p><strong>My Goal:</strong></p>
  
  <p>The ideia is very simple, when you roll the view first the AppBar Collapse in the Toolbar and after that the RecyclerView start to scroll.</p>
  
  <p><strong>My Hierarchy:</strong></p>
  
  <p>My Fragment RecyclerView(vertical) has a Adapter-A with a new layout, and this adapter call a second adapter-B for the RecyclerView(horizontal).</p>
  
  <p>So I Have a struct like this:
  (is not a code, just to show how works)</p>
  
  <pre><code>Fragment AppBarLayout{..}
  Fragment Recycler View (Vertical) {
      Adapter-A Text;
      Adapter-A Recycler View (Horizontal){
          Adapter-B Img;
          Adapter-B Text;
      }
  }
  </code></pre>
  
  <p><strong>What is the problem:</strong></p>
  
  <p>If I click in the RecyclerView(Vertical) or Adapter-A Img it works fine.</p>
  
  <p>But If I click in Adapter B content(Img and Text) it scroll both Recycler Views but not the AppBar.</p>
  
  <p><strong>What I'm doing:</strong></p>
  
  <p>I use </p>
  
  <blockquote>
    <p>app:layout_behavior="@string/appbar_scrolling_view_behavior"</p>
    
    <p>recyclerList.setHasFixedSize(true)</p>
    
    <p>recyclerList.setNestedScrollingEnabled(true);</p>
  </blockquote>
  
  <p>in both Recycler Views.</p>
  
  <blockquote>
    <p>app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlways"</p>
  </blockquote>
  
  <p>in the CollapsingToolbarLayout</p>
  
  <p><strong>I try to make this in java code:</strong></p>
  
  <pre><code>        recyclerList.addOnScrollListener(new RecyclerView.OnScrollListener() {
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              super.onScrolled(recyclerView, dx, dy);
              // If AppBar is fully expanded, revert the scroll.
              if (!shouldScroll) {
                  recyclerList.scrollToPosition(0);
                  //Here I should make the AppBar Scroll, but AppBarLayout.scrollTo(dx, dy) don't work.
              }
          }
      });
  
  
      mainHomeAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
          @Override
          public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
              shouldScroll = verticalOffset != 0;
          }
      });
  </code></pre>
  
  <p><strong>My code:</strong></p>
  
  <blockquote>
    <p>mainHome.xml</p>
  </blockquote>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
  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"&gt;
  
  &lt;android.support.v7.widget.RecyclerView
      android:id="@+id/main_home_list"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /&gt;
  
  &lt;android.support.design.widget.AppBarLayout
      android:id="@+id/main_home_app_bar_layout"
      android:layout_width="match_parent"
      android:layout_height="192dp"
      android:background="@drawable/gradient_bg"&gt;
  
      &lt;android.support.design.widget.CollapsingToolbarLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlways"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:layout_width="match_parent"
              android:layout_height="50dp"
              app:layout_collapseMode="pin" /&gt;
  
      &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  &lt;/android.support.design.widget.AppBarLayout&gt;
  </code></pre>
  
  <p></p>
  
  <blockquote>
    <p>mainHome.java</p>
  </blockquote>
  
  <pre><code>@Override
  protected void assignViews() {
      mainHomeList = (RecyclerView) findViewById(R.id.main_home_list);
      mainHomeAppBarLayout = (AppBarLayout) findViewById(R.id.main_home_app_bar_layout);
  }
  
  @Override
  protected void prepareViews() {
      mainHomeList.setHasFixedSize(true);
      mainHomeList.setNestedScrollingEnabled(true);
      linearLayoutManager = new LinearLayoutManager(getApplicationContext());
      mainHomeList.setLayoutManager(linearLayoutManager);
      initAdapterIfNecessary();
  if (mainHomeList.getAdapter() == null)
          mainHomeList.setAdapter(adapter);
  }
  </code></pre>
  
  <blockquote>
    <p>adapter-A.java</p>
  </blockquote>
  
  <pre><code>public class MainHomeModulesAdapter extends RecyclerView.Adapter&lt;MainHomeModulesAdapter.GroupViewHolder&gt; {
  
  private OnListItemClickedListener onListItemClickedListener = null;
  private OnListItemClickedTwoListener onListItemClickedTwoListener = null;
  private ArrayList&lt;JSONMainModule&gt; mainModules = new ArrayList&lt;&gt;();
  
  @Override
  public MainHomeModulesAdapter.GroupViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      Context context = parent.getContext();
      View itemView = LayoutInflater.from(context).inflate(R.layout.a_main_home_module_item, parent, false);
      return (new MainHomeModulesAdapter.GroupViewHolder(itemView));
  }
  
  @Override
  public void onBindViewHolder(MainHomeModulesAdapter.GroupViewHolder holder, int position) {
          //Place where put layout information
          holder.mainHomeModuleList.setLayoutManager(new GridLayoutManager(context, Utils.calcGridSpaceCount(context, 2))); //For two elements
          holder.mainHomeModuleList.setAdapter(holder.mainHomeContentAdapter);
          holder.mainHomeContentAdapter.updateListContent(mainModules.get(position).getModuleContent(), mainModules.get(position).getModule());
  }
  
  @Override
  public int getItemCount() {
      return mainModules.size();
  }
  
  public void setOnListItemClickedListener(OnListItemClickedListener onListItemClickedListener) {
      this.onListItemClickedListener = onListItemClickedListener;
  }
  
  public void setOnListItemClickedTwoListener(OnListItemClickedTwoListener onListItemClickedTwoListener){
      this.onListItemClickedTwoListener = onListItemClickedTwoListener;
  }
  
  public void updateListContent(ArrayList&lt;JSONMainModule&gt; mainModules) {
      this.mainModules = mainModules;
      notifyDataSetChanged();
  }
  
  public JSONMainModule getListContent(int pos) {
      return mainModules.get(pos);
  }
  
  class GroupViewHolder extends ParentViewHolder {
      TextView mainHomeModuleText;
      Button mainHomeModuleBtn;
      RecyclerView mainHomeModuleList;
      MainHomeContentAdapter mainHomeContentAdapter; //Adapter-B
  
      private GroupViewHolder(View itemView) {
          super(itemView);
          mainHomeModuleText = (TextView) itemView.findViewById(R.id.main_home_module_title);
          mainHomeModuleBtn = (Button) itemView.findViewById(R.id.main_home_module_btn);
          mainHomeModuleBtn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (ATUtils.isDoubleClick()) return;
                  onListItemClickedListener.onClicked(getAdapterPosition());
              }
          });
  
  
          //Child - Main Contents
          mainHomeModuleList = (RecyclerView) itemView.findViewById(R.id.main_home_module_list);
          mainHomeModuleList.setHasFixedSize(true);
          mainHomeModuleList.setNestedScrollingEnabled(true);
  
          mainHomeContentAdapter = new MainHomeContentAdapter();
  
          mainHomeContentAdapter.setOnListItemClickedListener(new OnListItemClickedListener() {
              @Override
              public void onClicked(int pos) {
                  onListItemClickedTwoListener.onClicked(pos, getAdapterPosition());
              }
          });
  
      }
  
  }
  }
  </code></pre>