Skip to content

alishaalam/Custom-Lists-Recyclerview-CardView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multiple Views - Recyclerview-CardView

Libraries used

  • RecyclerView
  • CardView
  • GooglePlay Services
  • Volley
  • Jackson


Project Features Description

  • Google Play Services​- To find out user location
  • Jacskon​- A library to deserialize JSON data using Object Mapper
  • Volley​- To start the request to get the JSON data using custom
    • Volley is faster than using AysncTask
    • It takes care of network handling internally
    • Caches data
    • Allows us to cancel requests attached to a Tag
    • It allows us to create a Custom Request class to execute our request
  • I have created a custom request class for using in Volley called ​JacksonRequest
    which extends JSONRequest
  • JacksonRequest​allows me to get the JSON response I need using volley and
    Jackson’s Object mapper.
  • Using RecyclerView and CardView for smooth scrolling and view re-usability
  • A ViewType and a ViewHolder for each card type so that different card types can be
    added in the future.
    • Used a LinkedHashSet to eliminate overlapping content

Additional Functionality
1. Cards can be re-ordered by a long press and drag
2. Cards can be swiped right to delete a card
3. Infinite scrolling is implemented. To show infinite scrolling scrolling i have created a few cards of the ‘Place’ type

 

Q: How would your implementation handle adding 20 more types (e.g. places, movies, events, videos, travel, etc)?

  • Add a new ViewType
  • Create a new ViewHolder and the corresponding layout
  • Hook it all up in the adapter

Q: How does adding 20 more types affect the performance of the app?

  • Recycling views improves performance by avoiding the creation of unnecessary views or performing expensive findViewById() lookups.
  • For each type of card created the method onCreateViewHolder() is called.
  • Each call to onCreateViewHolder() leads to creation of a new instance of ViewHolder
  • If there are 20 types and 1 item of each type in the list, onCreateViewHolder() will be called 20 times to create a view for every item.
  • If there is 1 type and 20 items of each type, depending on the screen size, lets 7 items fit on the screen, then o​nCreateViewHolder() will be called approximately 8 ­to 9 times.
  • Also, onCreateViewHolder() is not called when we view already created
    items, eg. while scrolling up/back in a list
  • Having too many types defeats the purpose of ViewHolder pattern. It does not allow us to reuse the views as we don’t have access to s​crap views which are cached

Q: What if these cards are visible in many different locations in the app?

  • To use these cards across multiple lists we can use RecycledViewPool
    RecycledViewPool lets us share Views between multiple RecyclerViews.
  • If you want to recycle views across RecyclerViews, we create an instance of RecycledViewPool and use setRecycledViewPool(RecycledViewPool)
  • RecyclerView automatically creates a pool for itself if you don't provide one.
  • This has a method setMaxRecycledViews

About

Recyclerview - Lists & Cardview

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages