Search code examples
androidviewreturnadapter

How to get/return viewtype in use from adapter?


is there a way I can get/return a View in my case a RecyclerView from the Adapter using it so as to reuse it in another Activity. And if possible how can I then re use it in the Activity?Without re-referencing it a new in the Activity


Solution

  • If I understood your question right, you are asking whether an Adapter for RecyclerView you have in an Activity can be used for another RecyclerView in another Activity. In that case, the answer is - YES, it can be used in as many places you wish..

    Don't forget, Adapter is nothing but a design pattern in programming:

    Adapter pattern works as a bridge between two incompatible interfaces. This type of design pattern comes under structural pattern as this pattern combines the capability of two independent interfaces.

    As long as you have your Adapter class accessible (not a private inner class) by your other Activity, you can reuse it with different RecyclerView and different data.