Posts

Showing posts with the label LinearLayoutManager

using LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager with RecyclerView

Image
In the Previous Post , We have created a Recycler View with list of items like listview, Now we will see how simple to make a gridLayout and |StaggerdGrid with Recycler View by simply modifying the code in the method  to show the items in different ways in the UI .   mRecyclerView.setLayoutManager(glm); LinearLayoutManager ================= mRecyclerView = ( AutofitRecyclerView ) findViewById ( R . id . my_recycler_view ); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView . setHasFixedSize ( true ); LinearLayoutManager llm = new LinearLayoutManager ( this ); // use a linear layout manager to show items like listview mRecyclerView . setLayoutManager (l lm ); // create an Object for Adapter mAdapter = new CardViewDataAdapter ( myDataset ); // set the adapter object to the Recyclerview mRecyclerView . setAdapter ( mAdapter ); ScreenShot: GridLayoutManager  ================ mRecycler

RecyclerView with onClick and onLongClick implemtation in android example

Image
In the Previous Post , We have create list of items with RecyclerView using appcompat v7. Now, we have implemented onclick event functionality in the previous post for each list item using stackoverflow link. Now, I have update the code to latest Android Api RecyclerView default way of implementing onClick and onLongClick on the each item. Step 1 : Create an Activity with recyclerview CardViewActivity.java package com . pratap . cardviews1 ; import android.os.Bundle ; import android.support.v7.app.ActionBarActivity ; import android.support.v7.widget.LinearLayoutManager ; import android.support.v7.widget.RecyclerView ; import android.support.v7.widget.Toolbar ; public class CardViewActivity extends AppCompatActivity { private Toolbar toolbar ; private RecyclerView mRecyclerView ; private RecyclerView . Adapter mAdapter ; private RecyclerView . LayoutManager mLayoutManager ; @Override protected void onCreate ( Bundle savedInstanceState ) { super . onCreate ( sa