I have 2 activities in my application and I have a RecyclerView that should be in both of them.
Is there any way to share this RecyclerView with these activities or I have to define this RecyclerView in both of them separately?
(I don't want to use fragments in this app)
Thank you for your answer.
You could probably create a 'base' activity and share the layout between the two activities by extending it and use setContentView . You can read more about this here
Related
I am stuck with a problem where I have designed a tab layout that I have used as a library in the current project which has a Recycler View. I want to show the tab layout on top and the recycler view under the tab layout.
For reference in Whatsapp, there is tab layout under which there is a recycler view that shows all the messages.
Problem is that I am confused about how to combine both activities together so the user can use the tab layout.
If anyone knows any solution please help!!
Use single-activity pattern. This pattern means that you need to use Fragments in a single activity (MainActivity, etc). Additional tip, you can use ViewPager2 with TabLayout for your Fragments.
Activities can't be composed into one, cause it designed so.
I have 2 Activities- MainActivity and SecondActivity. Both activity contains recyclerview with same layout. So, i can easily use the same adapter and xml layouts for the recyclerviews.
But is it a good practice? My confusion is that - if both activities are live and using same xml resource isnt there going to be a problem? plus they are going to use same adapter.
Is this a good practice or bad ?
Multiple activities can use the same XML layout without problems, as they don't share actually inflated views. (Every activity inflates its own layout from given XML.)
I would recomend not to share the same adapter INSTANCE between activities - better make separate adapter-instance for each activity. (You can reuse adapter-class in multiple activities, if you need to do so.)
I want to divide my screen into four parts and add activities in each part. I am not interested in using fragment. Each activity should behave independent of other. Attached photo is showing what I exactly want to do.
In each child activity I want to add VideoView or WebView depending on the selection from menu item.
How can I do it. I didn't find any way to add activity to an activity.
Thanks :)
PS: Activity means Activity not fragment.
i strongly recommend 'using fragments' in your case as ActivityGroup is deprecated in API 13..
The only way you can do it by using fragments. Here is the simple example on how to add multiple fragments on single activity Link
Edit link
You can achieve this design by using four fragments, one for each child view inside a single activity.
The recommended way is to create a single XML layout for your activity, and create four fragments inside that layout.
I'm kind of new in Android and i'd like to know if there is a way of displaying a xml file (with the same 'controller') from different activities?
In other words, I'd like to display a list of CardViews with the same content and listeners in two different activities (exactly the same way). What is the best way of doing it?
There's ways to do this if I understand right.
You can use same xml in different Activities.
You can start same Activity twice.
You can use fragment to display same content.
I've read at a few places that I should not be using Activities as contents of my tabs. I would like to know why this is not a recommended approach... Any suggestions?
I'd flip it around: why would you want to use activities as tabs? All you do is add overhead and complexity. Just use Views for the tabs.
If you have something that just has to be both a tab and a separate standalone activity, reuse the View.