How to share adapter items with two recycler views? - android

I am trying to implement Instagram like Search fragment where they have explore posts(contains only the image) in a grid layout and when we click on them, it changes to another feed like view showing more details.
The way I am thinking to implement is to have two fragments with recycler views: 1 for grid layout and 1 for feed like. Share the currently, loaded feed items between these two recycler view adapters.
Question: Is it the correct approach to share adapter items between two views? If not, what would the design be? I suspect I will run into issues if we share the items.
Kindly let me know if any more details is needed. I can share pictures as well in case someone needs for android device.

I went ahead and implemented my design. Till now, I haven't seen any issues.

Related

Android Fragments In A List View

I have looked everywhere for examples on how I can have individual fragments set up as in a list view. It seems either this is highly not recommended or not possible. Does anyone have examples that I can look at? Essentially the app that I am trying to build is a an e-commerce app with a list of items to purchase. I know it may be overkill to have every item to be listed as a fragment but for this project, I need to do this.
This is highly not recommended. If your using a ListView then your xml layout file for each list item will be the same. Ideally if you use a ListView your elements will be mostly the same. You could have one Fragment for when an item is selected from your ListView, however. This one Fragment will be able to function properly for all elements of the ListView. That way you only have on Fragment for all of the elements in your ListView. Having a Fragment for each item in a ListView would be very inefficient.

Android List view row move vertical

I want to create List view row animation like below . I want to move row from one list view to other list view. Both list view are in same activity.
Anyone can give me idea how I can do this.
First of all because you mentioned "ListView":
In my opinion the best way to perform dynamic "lists" in android is to use to android-given class
RecyclerView.
It's easy to use like a normal ListView but like I said before it handles dynamic data.
Moreover it has some support librarys like ItemTouchHelper to drag/drop and swipe items in the list around. Its very easy to expand your RecyclerView with this upgrade. Here is a good tutorial:
Tutorial.
I would like to give you two ideas how I would proceed to implement such a list like the example of your post:
1) (Recommended) Search on Github or similar sites for 3rd library parties that already solved this.
2) Use the RecyclerView with the ItemtouchHelper-Upgrade i mentioned above and try to expand it with two lists. When an item is onMove() set the visibility of the first list on GONE and the second on VISIBLE. Now you only have to add the data of your item to the second list and remove it from the first. Then use notifyDataSetChanged() on both lists and your done.
I dont know how difficult it will be to implement it but thats the only way I know how you can do that and how the programmers of your example could have done it.

Design a Grid view with categories and load images on demand in android

I want to create a grid view similar to the image shown below. The category panel
can be scrolled horizontally and has a list of items. When clicked on a category the grid view is loaded dynamically and selected category is underlined/highlighted. Grid also loads images on scroll vertically as well.
Currently, I download a xml with images to a gridview and use Picasso library to load images.
What I want to know is
1) how to add the categorizing to my current implementation?
2) Do I load a single xml with categories and image list first and then load images after or do I keep a xml per category.
3) How do I manage the grid adapter when user clicks on different categories
4) How do I design the category scroll view at top?
Well, after reading the question thoroughly your not asking for a Solution, your asking a Suggestions !!
So, i come up with some approaches to guide you regarding the implementation.
As you mentioned in your question, you have different different categories and each of the category having the grid of images. one main hing is like you can select the category / you can swipe the grid view to change another category in your app.
Why not, these all you can do. Did you used Fragments & ViewPager ?
by combination of Using ViewPager with FragmentPagerAdapter you can achieve the same what your planning.
Here i am explaining you in details >>
your category size is fixed ?
if yes you can make static fragments for those. if it is not fixed in a size / order then you can create PageAdapter with the list of your categories and set that adapter to your view pager in home screen
Now you have a categories, After that you can create a corresponding fragment activity to hold a gridview and based on the page adapter position you can load the categories into the gridview
Here your all fragments having the same gridview, so you easily control it by using vie pager and respective gridview loading and controls you can made in the fragment.
By using this, there is no way of creating such no of xml files & classes as you mentioned in the question. It is a simple and easy way to handle
The big advantage in this approch is like, you no need to bother about the size of categories (as your making as adapter, 35,50,100 that number go's on) it will add the categories to your view pager
fragment loading also you can make a single fragment and re-use the same in all over application as every category having the same grid view .
Here is a sample example to use the fragments with gridviews in a view pager and this
Also you can find a lot of examples in SOF like this..
if you find any difficulty then come with a piece of code/trail what you did and ask in SOF.
Let me if any clarifications required.

Google Currents like Viewpager + adapter (not indicator)

I'm learning how to build an adapter like the one demonstrated in Currents.
I know the basic classes used to achieve what we see in currents : ViewPager, ViewPagerIndicator, and a custom view showing 6 ImageViews and textviews below it.
My question is, how do we go about building a custom adapter that will automatically fill in 6 items in the first viewpager page, and continue filling it on the next page automatically? I'm guessing it will be something along the idea where the number returned from getCount() will be used to determine how many viewpager "pages" are there, (in this case divide by 6 ).
I have successfully tried building a similar view using GridView + viewpager+indicator, but i'm sure Currents is not using gridview to achieve this. Since this is definitely not extending ListView nor GridView, how can i go about solving this? Thanks in advance.

Custom Adapter for Gallery View in Android

hi i want to split my gallery with 5 images in 2 rows.
Please let me know how to do this in android using Gallery View & custom adapter for Gallery view.
Is there any sample code available please share it, i have already checked the previous posts in this site.
Thanks
If you still need this and Pagination instead of scroll will work for you, you might look at: https://github.com/sfarooq/PaginatedGallery
I designed it using ViewPager so you can manipulate the adapter to send any kind of views you want including two row views.
If you must use scrolling galleries you could implement two separate gallery in a vertical orientation and send touch events from each to the other.

Categories

Resources