1. Download our Official Android App: Forums for Android!

Apps RecyclerView Behavior

Discussion in 'Android Development' started by MickyOwly, Apr 24, 2016.

  1. MickyOwly

    MickyOwly Lurker
    Thread Starter
    Apr 24, 2016

    Apr 24, 2016
    Hi, I'm quite new to Android Programming..

    Been doing some codes of the famous "Big Nerd" book,
    I've implemented a RecyclerView in my App, that includes an Holder, Adapter and "
    onCreateView" function which of course inflate the view to the screen.
    It's a basic case which I have a list of "Crimes" as text, and there are too many "Crimes" in the list to be placed on the screen so we use the RecyclerView.

    My question is about the behavior of the RecyclerView while the app is running.
    In the first app i've noticed that in Android, a buttons or other widgets are being defined as listeners and wait for the user to take an action, then function operate itself and the screen changes accordingly.

    But I don't see any listener that deals with the user swiping the screen and changes the view,
    Does that mean that the RecyclerView is accumulating all the needed data for the entire view and when the user is swiping the list RecyclerView is taking care of the changes with its function behind android scenes?

    Or does it mean that the Android system itself is getting the data from the Activity and the RecyclerView, then deal with such changes to the screen?

    Hope you understand my question,
    I'm attaching the crimelistfragment code that include the implementation of RecyclerView. Thanks.

    package com.bignerdranch.android.criminalintent;

    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.v7.widget.LinearLayoutManager;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;

    import java.util.List;

    public class CrimeListFragment extends Fragment {
    private RecyclerView mCrimeRecyclerView;
    private CrimeAdapter mAdapter;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_crime_list, container, false);
    mCrimeRecyclerView = (RecyclerView) view
    mCrimeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return view;

    private void updateUI() {
    CrimeLab crimeLab = CrimeLab.get(getActivity());
    List<Crime> crimes = crimeLab.getCrimes();
    mAdapter = new CrimeAdapter(crimes);

    private class CrimeHolder extends RecyclerView.ViewHolder {
    public TextView mTitleTextView;

    public CrimeHolder(View itemView) {
    mTitleTextView = (TextView) itemView;
    private class CrimeAdapter extends RecyclerView.Adapter<CrimeHolder> {
    private List<Crime> mCrimes;
    public CrimeAdapter(List<Crime> crimes) {
    mCrimes = crimes;
    public CrimeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
    View view = layoutInflater
    .inflate(android.R.layout.simple_list_item_1, parent, false);
    return new CrimeHolder(view);
    public void onBindViewHolder(CrimeHolder holder, int position) {
    Crime crime = mCrimes.get(position);
    public int getItemCount() {
    return mCrimes.size();



Share This Page