I have an application that sends a request to an API, where JSON data is returned and displayed. Depending on the user, there will be data for multiple locations with each location being a header and having its own listview. How would I do this in Android? I understand the concept of a single dynamic listview, but how would I generate MULTIPLE LISTVIEWS DYNAMICALLY?
Still not sure what do you mean by multiple listviews dinamically, and first of all why would you need this, but perhaps you just need an ExpandableListView?
A view that shows items in a vertically scrolling two-level list. This
differs from the ListView by allowing two levels: groups which can
individually be expanded to show its children.
Related
I want to create some CardView items dynamically, depending on items I get via a REST call. I created a CardView XML layout that contains many single elements with many settings. I don't want to write this XML layout in code to create it dynamically. Is there an easy way to do this work?
Each CardView item has its own name etc. therefore, the IDs of the elements inside the CardView must be different.
I think it would be a good idea that you take a look at this tutorial. https://guides.codepath.com/android/using-the-recyclerview
Basically what you want to do is create a basic CardView item, with its correspondent ViewHolder and inflate the contents of each item when you get the result from the API call.
I want to get the all values from the RecyclerView using Espresso. I am able to get only the visible values from the recyclerView. But not able to get the values which are visible when scrolling.
Ex. In RecyclerView 25 items are there and Only 7 items are visible. Others are visible when we scroll it. I am able to get the values of 7 items. But want to get all the values
Can Anyone please tell me how to get this
Thanks in Advance
You need to remember how RecyclerView really works. It optimizes showing scrollable elements, by displaying only items that are currently within the visible range.
In other words: before you scroll to items below, they are no Views within the RecyclerView to represent those items. Just the data in the Adapter.
So the way you should be probably doing your test is to:
Verify proper state of currently visible items.
Scroll the RecyclerView (using one of the RecyclerViewActions.scrollTo methods)
Verify proper state of currently visible items.
Scroll the RecyclerView.
...
I'm relatively new to programming and I'm facing the challenge of having 2 tabs in my activity. In each tab there should be a RecyclerView which is identical with the other.
My guess would be to update the datasource when the user switches the tab. So one activity with one RecyclerView cares about two tabs.
But as I read more and more about it people usually use fragments for each tab.
Why? Which approach is better?
If you use fragments, you have two lists so you can properly implement dragging between pages, and returning to either tab will properly keep current scroll. You can also keep data for each tab in separate fragment, which breaks down huge source files into something more manageable.
Tip for using multiple RecyclerViews with same item types is creating single RecyclerView.RecycleViewPool and keeping reference in activity to reduce number of ViewHolders you need to create.
What is the difference between a listview layout xml and a Listview Java class? I am trying to make it when a user inputs text and presses enter it comes on a set position on the right but when the user receives a reply it would show up on the left side of the list view. Like text messaging on android phones. Does anyone know how i can do this? With a java class or an xml layout? I want animations and dynamic content on the listview as well. Any ideas?
ListActivity provides you all the built-in features of and methods of ListView but only ListView can be added into the whole Activity. By using ListView in xml, you add multiple Views such as Buttons, EditText on the same Activity.
Basically, the xml is for seperating the design (the visuals) from the code (functionality).
Although you can do some funcationality via xml, it's usually better to do it in Java code in your class.
I guess you can create a ListView that will iterate through 2 different list enteries:
The first will show the data (the text in your case) on left and the second entry will show on the right. For each list entery you will create a different xml layout with widgets aligned to the left and right as needed.
I'm working on an android application and I have run into a decision that I can't decide on one way or another. I was hoping someone could shed some light on the common practices and any theory to back them.
Here's the issue:
I want to have a list of items with images and text like table...
Country -.-.-.-.-.-.- Pop -.- SqrMi
[img] US -.-.-.-.-.-.- xxx -.-.- xxxxx
Now the debate I'm having is whether or not to use a listview to display the data or instead nest a layout that is scrollable and just display the data that way.
Why would I even consider a nested layout? Flexibility. I can design the dividers, possibly throw in a couple graphs above/below the list. Vary the height of each of the list items (like what if I want to show a graph in one list item and no graph in the next), etc.
I'm not sure if I'm breaking the generally accepted methods here. Can anyone shed some light on this?
The only major problem you will have when using nested layouts is memory consumption. ListView reuses its children so it doesn't create more children then it can display at a single moment. This description is a little simplified but I hope it shows the purpose of the ListView. Also ListView implements its own fast scrolling so it doesn't have to measure all its children to determine its size. And ListViews use adapters to populate themselves with data. It's a nice and convenient way to obtain data.
On the other hand if you create a ScrollView with a lot of views inside it'll be slow, difficult to populate with data and it'll require a lot of memory to create all of the child views even if you don't ever see some of them.
And about flexibility of the ListView. You can store different types of view in a single ListView and you'll be able to vary the height of each of this views.
All the things you have described for your "nested layout" is achievable with ListView. Just use different types of rows, use headers/footers in adapter.
And as already Pixie said, ListView is much more memory efficient and faster.