3

I have an activity which displays an AppToolbar alongside a RecyclerView which is located below the Toolbar. Every row of the RecyclerView is a CardView. My problem is that the RecyclerView doesn't scroll at all. It seems that it doesn't receive any gesture callbacks.

Here is my main layout xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    android:fitsSystemWindows="true"
    android:background="@color/colorActivityBackground"
    tools:context=".MainActivity">

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/rv"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:scrollbars="vertical"
            android:fadeScrollbars="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


    <include layout="@layout/tool_bar" />

    <include layout="@layout/nav_drawer_layout" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_add"
        app:layout_anchor="@id/rv"
        app:layout_anchorGravity="bottom|end" />

</android.support.design.widget.CoordinatorLayout>

Edit: Here is the tool bar code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="false"
    android:theme="@style/AppTheme.AppBarOverlay"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:elevation="4dp"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>

Here is also my nav drawer layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?attr/actionBarSize">

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- The main content view -->
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <!-- The navigation drawer -->
        <android.support.v7.widget.RecyclerView
            android:id="@+id/right_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#99ccff" />

    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

And here is my Main Activity where I populate my recycler view:

package bikurim.silverfix.com.bikurim;

import android.app.SearchManager;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import java.util.ArrayList;

import bikurim.silverfix.com.bikurim.adapters.MenuDrawerAdapter;
import bikurim.silverfix.com.bikurim.adapters.RecyclerViewAdapter;
import bikurim.silverfix.com.bikurim.items.FamilyItem;

public class MainActivity extends AppCompatActivity {


    private ArrayList<FamilyItem> families = new ArrayList<FamilyItem>();
    private ArrayList<bikurim.silverfix.com.bikurim.items.MenuItem> items = new ArrayList<bikurim.silverfix.com.bikurim.items.MenuItem>();
    private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle drawerToggle;
    private RecyclerView recyclerView, menuView;
    private RecyclerViewAdapter adapter;
    private MenuDrawerAdapter navAdapter;
    private SearchView searchView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_families);
        // Setting up the tool bar
        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        // Setting up the main lists and their adapters
        fillList();
        createMenuItems();
        recyclerView = (RecyclerView) findViewById(R.id.rv);
        menuView = (RecyclerView) findViewById(R.id.right_drawer);
        adapter = new RecyclerViewAdapter(families);
        navAdapter = new MenuDrawerAdapter(items);
        // Default Animator
        DefaultItemAnimator animator = new DefaultItemAnimator();
        recyclerView.setItemAnimator(animator);
        menuView.setItemAnimator(animator);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        menuView.setLayoutManager(new LinearLayoutManager(this));
        menuView.setAdapter(navAdapter);
        Log.d("Menu Items Count:", ""+navAdapter.getItemCount());
        // Setting up the navigation drawer side-menu with DrawerLayout
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) {
            /** Called when a drawer is in closed state. */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                getSupportActionBar().setTitle(R.string.app_name);
            }

            /** Called when a drawer is in open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getSupportActionBar().setTitle(R.string.drawer_name);
            }
        };
        drawerLayout.addDrawerListener(drawerToggle);
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Does absolutly nothing, yet!", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
    }

    private void fillList() {
        families.add(new FamilyItem("Ohayon", "12:36"));
        families.add(new FamilyItem("Zohar", "14:23"));
        families.add(new FamilyItem("Lasry", "15:55"));
        families.add(new FamilyItem("Zambuzak", "17:45"));
        families.add(new FamilyItem("Cohen", "11:33"));
        families.add(new FamilyItem("Tapera", "09:25"));
        families.add(new FamilyItem("Ochuya", "09:25"));
        families.add(new FamilyItem("Konichiwua", "09:25"));
        families.add(new FamilyItem("Kontaktiwa", "09:25"));
    }

    private void createMenuItems() {
        items.add(new bikurim.silverfix.com.bikurim.items.MenuItem(R.drawable.about, "עזרה"));
        items.add(new bikurim.silverfix.com.bikurim.items.MenuItem(R.drawable.settings, "הגדרות"));
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        drawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        drawerToggle.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_families, menu);
        SearchManager searchManager =
                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
        searchView.setSearchableInfo(
                searchManager.getSearchableInfo(getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                adapter.getFilter().filter(query);
                return true; // handled
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                adapter.getFilter().filter(newText);
                return true;
            }
        });
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (drawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_search) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
alainlompo
  • 4,414
  • 4
  • 32
  • 41
David Lasry
  • 1,407
  • 4
  • 26
  • 43
  • From what you've posted it all looks like it should work. Post tool_bar, nav_drawer_layout, and the code you use for populating the recyclerview. – Da-Jin Jun 09 '16 at 19:20
  • I added these codes to the post – David Lasry Jun 09 '16 at 19:33
  • Wow you have a lot going on in there. I'm not very familiar with DrawerLayout, but I don't think you are using it as intended, and I'm confused as to why you have 2 recyclerviews. Check out this answer for how Coordinator, AppBar, and Drawer layouts should interact: http://stackoverflow.com/a/33413334/1224186 – Da-Jin Jun 09 '16 at 19:42
  • The second recycler view is for my navigation drawer menu – David Lasry Jun 09 '16 at 19:48
  • Did you get any solution? – user4057066 Jan 31 '17 at 10:22

0 Answers0