I am doing a small Android game where the user needs to assign two players to two teams.
My plan is to use a recycler view which lists all existing players (which are stored in a local database).
The items in the recycler view will be possible to reorder. The first two items in the recycler view will be assigned to team A and the next two items will be assigned to team B. The remaining players will not be considered in a team. The implementation of this logic will be fine, there are also enough examples in the web.
But in order to indicate this logic to the user, I would like to offer him some kind of boxes which indidcate the teams. Like in the following wireframe:
Does anybody have an advice how this should be done? Should I put a View above the recycler view?
Alternatively, I am also open for alternative approaches to assign exactly two players (uniquely) to two teams.
If you want use RecyclerView, you need to include divider in item view, or make divider as item itself.
You need to place these Divider backgrounds below recyclerview, calculate heights of these items and place it accordingly.
Related
I'm aware of the DividerItemDecoration with regards to RecyclerViews although instead of a divider between every item I'm more interested in a divider whenever a certain attribute changes within my elements. For example, a list of transactions that hold the date by which they were posted - a divider would then display at each change in date in the list of transactions.
This is definitely possible but I'm just not sure to go about doing it. For example, in the Monzo application - it's the dates that separate the transaction lines.
Any help would be very much appreciated!
You would create a recycler view adapter with two viewholders. In the example of the Monzo app, you would create one ViewHolder for the purchase and the other for the date. Then in onCreateViewHolder you would inflate the correct type of viewholder for that item in that list.
One way you could do it is to add the divider to the ViewHolder layout, defaulting to View.INVISIBLE (or View.GONE if you want it to take up extra space when it's visible - like the divider is outside the list element instead of inside at the top edge)
Then in onBindViewHolder you could do a bit of logic to decide if the divider should be set to visible or not for that item - something that decides if it represents a date change, and make sure to check it's not the first item in the list too (don't want a random divider up there)
I have been working on an app that adds views programmatically to a linear layout.
The problem is if I add too many views it will go off the screen.
I would like to know how to check if a certain child has hit the end of the same view group so I could add it into another layout (a linear layout below the first one) before it "flows" and go off the screen. How might I accomplish this?
Rather than reinvent the wheel yourself, I suggest that you check out the FlexboxLayout project by Google: https://github.com/google/flexbox-layout
A FlexboxLayout will automatically give you the behavior you're describing, plus the potential for much more.
Well, there are a good number of ways you could implement this in android other than going through this hustle. What ever you are trying to do at the moment may fall under one of the following cases.
Creating views programmatically most likely means you have a dynamic data set probably from an external source.
Your dataset is limited or static but just more than the average screen can display.
if any of the above apple then you are better off using a ListView or RecyclerView (Recommended). That way your data is full displayed as a scroll-able list and you don't have to worry about some items or views not showing or going of the screen. This can range from simple string list to complex nested views.
This will be very efficient as it will automatically handle optimization and usage of memory as well as performance.
What I want to create
I want to create a list where each item in that list is an data table like below: The user needs te be able to sort items in the data table and needs to be able to sort the data tables itself.
Each table is going to represent a client and each item in that table is an order. The user will then collect the orders, if he collected an order the order wil dissapear but the user is also able to bring them back.
What I tried
I tried to put a Recyclerview inside a Recyclerview but this caused unitended side effects and bugs, also I read online that it is basically a bad practice. My initial intention was to use a recylcerview with a sortedlist.
I did some searching online and a lot of people recommended using categories between items so that you only need one list. But because I have data tables (CardViews) that can be independent sorted this isn't an option.
If anyone want to give me a nudge in the right direction, I would be really thankful.
What you can do you can use recycler view and in custom row check box with 8 text views and when position is 0 inflate categories like fat, calcium etc and after that position populate data and if you want next button which shows next items in list use fragments or pagination that should do the trick and you can achieve this using single recycler view. You can also use header to show categories.
is it possible to make an expandable list within an expandable list
i am making a recipe application and i've three expandable lists of the same type - vitamins, minerals and macro-nutrients created with expandablelistview with android studio
is it possible to put these three expandable lists under an expandable list called nutrition and if so could you briefly outline how please. thanks in advance
Short answer, yeah you can but you really really shouldn't.
I've tried this before and it didn't end well, I can't remember the exact reasons but conflicts arise between touch listeners and the measure passes when trying to layout the views inside the different adapters don't calculate correctly.
You can find a number of custom ExpandableLists trying to do what you want around the web but I found they also had similar issues.
What I ended up doing was building my own expandable listview. If you check the source code for Android's ExpandableListView and ExpandableListAdapter you'll find that it's basically
just a regular listview
a list of items that are visible
an Async filter for the data source
some meta data to tell if its a child or group, expanded or collapsed, etc
So if all your item are collapsed the visible list only contains the Group Items.
Expand a Group Item and the async filter gets triggered and populates the visible list with the Group Items and the Children of the expanded Group Item.
Depending on the meta data it will call either getGroupView or getChildView.
So if you want you can take a shot at writing your own.
I wrote a blog post for an ExpandableList that I wrote that does, in theory, infinite levels of expansion. NLevelExpandableListView
I've a ListView with items containing information about places with a rating and the distance to the current location.
The items are sorted into groups:
Group 1: within 500m
Group 2: 500m - 1km
Group 3: 1km - 1.5km
...
Withing these groups the items are sorted by their rating.
Now I put out these items via my custom adapter (extension of BaseAdapter) into the ListView, which works perfectly.
However, what I'd like to do is to put a separator before the each first item of each group. This separator can be a TextView saying e.g. 500m - 1km followed by all the ListView items in that group.
Any idea on how to realize this?
Here is one implementation that does exactly what you describe.
That one is GPLv3, because it is derived from this implementation, which was GPLv3.
You can also use my MergeAdapter for this, which has the advantage of being Apache License 2.0. Just hand it an alternating set of header TextViews and Adapters containing each section's worth of content.
Or, you can peek at all of these and roll their behaviors into your existing Adapter class. The trick is to return your TextView headers at the right spot, and properly implement methods like getViewTypeCount(), getItemViewType(), areAllItemsEnabled(), and isEnabled().
Here is even nicer implementation, inspired from iOS section list view : http://code.google.com/p/android-section-list/. The nie thing about it is that the section header remains visible even if you scroll the section down.