• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps RecyclerView Behavior

MickyOwly

Lurker
Apr 24, 2016
1
0
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;

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

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

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

public CrimeHolder(View itemView) {
super(itemView);
mTitleTextView = (TextView) itemView;
}
}
private class CrimeAdapter extends RecyclerView.Adapter<CrimeHolder> {
private List<Crime> mCrimes;
public CrimeAdapter(List<Crime> crimes) {
mCrimes = crimes;
}
@override
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);
}
@override
public void onBindViewHolder(CrimeHolder holder, int position) {
Crime crime = mCrimes.get(position);
holder.mTitleTextView.setText(crime.getTitle());
}
@override
public int getItemCount() {
return mCrimes.size();
}
}

}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones