How to create listview and title (dynamically) in Android programmatically? - android

I am really confused, which among GridView, Tableview or multiple listview to be used to develop a UI as shown in below image.
I don't know how much list data (categories and its sub categories) is in web. It is dynamically added from wed, and sent to my android app.
Please suggest me, what view is best for developing above UI.
Note: I want to make it programmatically.
Thank you in advance for your co-operation.

Keep in mind that the image you have shown as an example is quite large and such an implementation would make for a cluttered UI on smaller screen sizes. That being said, the example you provided could be achieved in Android by using a GridView. Each major category (Automotive, Jobs, etc.) would be a grid item, with the sub element implemented as either a TextView or even a ListView within the grid item. Something like this:
As both #PedroHawk and #bryan mentioned, you could also use an ExpandableListView; in this scenario, the major categories (Automotive, Jobs, etc.) would be header items and the sub elements would be children of the header. Something like this:
However, with this implementation you would be limited to a one-dimensional list - that is you would not be able to have major categories next to each other as shown in your example.
With both of these implementations (ExpandableListView and GridView) you can dynamically add more elements as you receive data.

Like PedroHawk said, ExpandableListView is an option. But also consider because of the screen size, you may not want to try and port the UI directly over. What about a single ListView with just the main categories and the user can drill down?

Related

Android Complex list of items in scrollview Best Practices

I´m developing an app in which I have a list of products, sometimes are a huge list and other times are only one or two items.
I read this items from a local database, right? ok, when I have about 20 o 30 items, I think the return is very slow, it takes one or two seconds rendering items and I need to know the best practices about that.
I have tested two ways:
The more tricky (I think), is creating views programmatically and adding to the scrollview as childs of the linearlayout inside.
The best for design: having an item-theme in a xml and inflating once by each item.
Is there a better way? I´m sure yes!
My items are a little bit complex:
image, name, category, provider, price, some buttons with "onclick" listeners, two little icons. Everything each item.
It is very important for me to speed up that process.
you can use listview and use the attr :
android:descendantFocusability=”blocksDescendants”
it can make your item widget respond some click or touch
My first thoughts on what you described are:
Create an xml layout for the listing
When you get the full list of items, store listing data somewhere
Inflate 5 (or 10 or whatever a reasonable amount of might be) listing layouts into the scroll view and use the data to fill them
Use a listener to check when the user has scrolled to the bottom of the scroll view... or halfway down or whatever you choose
Inflate the next set of items if they exist
This should prevent the slowdown and if you implement it correctly the user won't even know they aren't all loaded.
I think you need to implement a scroll view type to do this... do some searching for the scrollviewlistener.
It should be pretty straight forward.
I found the answer. Really cool.

Google Play Music style GridView

I'm looking to create a music app and I'd like to make a GridView similar to what Google Play uses where they inject elements that will span rows and columns like the Soilwork album does in this screenshot:
I've thought about using a ListView and populating rows with custom elements, but I couldn't think of a good way to use that with ViewHolder pattern, or really a way to make that reusable and account for differing number of items in width based on screen size (for example, the grid is only two items wide on phones, and "large" items span both columns and only one row).
I've also thought about using a ScrollView filled with custom ViewGroups, but that seems to run into the same issues I previously mentioned.
I next thought about using GridLayout, but that doesn't accept ListAdapters, and doesn't seem tuned to the kind of usage I'm looking at (nor does it seem to scroll)
I'd greatly appreciate if anyone could give me somewhere to start on this, or could point me to a library that does this. I've already checked out StaggeredGridView but it doesn't seem to accomplish what I'd like. My ideal solution would be a view which lays out items on an even grid like GridView and accepts view from a ListAdapter, also like GridView, but allow for elements to span, using the single cell constraint of GridView as the default behaviour.
Cheers.
EDIT
I have a perfectly functioning GridView as shown below, but I'd like to make items at regular intervals (every nth item) span more than one column and/or row, as shown in the previous screenshot.
Check out Parchment. GridDefinitionView may help you achieve the UI you are looking to build.

Android- Contact details UI layout

I'm building a contacts app and wanted to know what the best way of building something like the image below(Jessica is not too shabby...) in terms of using a list view, scrollview, etc.
Ideally, all of my data is in the sql database so a cursor adapter wouldn't be an issue. Is it better to have a listview with separators, or a scrollview where you add views. Since all contacts won't have exactly the same information, what can we do to make that? Any ideas would be greatly appreciated.
If you plan to have interactive elements inside of the items (e.g. the message button in the screenshot above) I'd recommend a ScrollView. Actually, since you probably don't have that many items I would again recommend a ScrollView. Then it's justa matter of having a set of layouts that you dynamically add depending on the information you have for the contact.

Is a simple 50 item list enough to justify using a ListView?

In the Google I/O 2010 talk about ListView they say you might not need to use a ListView with a bounded and reasonable number of rows. They state if you are dealing with a reasonable number of rows it is possible to just lay them out in a ScrollView.
I'm curious what people find "reasonble length" means in practice.
Would a list of 50 items with each row's views just having a few strings be reasonable to layout without using a ListView? How about 12?
I'm used to using UITableViews on iPhone for most UI so I'm inclined to use ListViews on Android but I also want to be aware it might be overkill for some scenarios and I have a really limited understanding of perf on android presently.
ListView is really the best option for anything over 3 items, it is a good option for even 2 or 3 items. If not you'll end up writing a bunch of code that converts indexes to individual variables instead of arrays, database rows, or other data structure.
It's not only about the number of items but also about whether or not your data collection will be dynamically updated. If you know you will never update the list while it's on screen and it doesn't have many items then a LinearLayout will do just fine.
In the Google I/O 2010 talk about ListView they say you might not need to use a ListView with a bounded and reasonable number of rows. They state if you are dealing with a reasonable number of rows it is possible to just lay them out in a ScrollView.
Hmmm, I can understand the logic up to a point but in reality using a ListActivity, for example, as your base class makes things very simple. OK, if you have a static list of only a dozen or so lines of text (one for each list 'item') then using a ScrollView containing TextViews would be an alternative but in reality using the adapter approach to ListViews is a lot more flexible in my opinion.
Would a list of 50 items with each row's views just having a few strings be reasonable to layout without using a ListView? How about 12?
No, if each list item has a few strings to be laid out then custom list item layouts together with a ListView and a custom adapter are basically a must.

Best practices combining list and non-list views, like the Market

I'm trying to tackle a problem that seemingly many Android developers have, which is how to intersperse lists with non-list data, in one big scrollable pane.
The model I have in mind is the screen for an individual app in the Market. You have a big description, a list of a few lazily loaded comments, and then some individual items that do different things, like visit the developer's web page, call them, etc. And then in between them all, are nice section headers.
Emulating this approach seems to be extremely hard. I've read enough SO answers and mailing list posts to know not to put a ListView inside of a ScrollView, but I want the same effect without using addHeader() and addFooter() with very complex header and footer views.
I've tried using a LinearLayout that I stock with views myself, but I can't get the pleasant click effects that default list items have (the orange background, white for long-click, etc.).
What do I do?
Take a look at my MergeAdapter, which is designed to handle scenarios like this.
Why not use a header? It's easy. Define the header contents in a separate layout. Your activity layout contains nothing but the ListView that you want at the bottom. No scroll view!
Then call
View headerView = getLayoutInflater().inflate(R.layout.header_layout, null);
ListView listView = (ListView) findViewById(R.id.my_list_view);
listView.addHeaderView(headerView, null, false);
It's crucial to call that form of addHeaderView so that the header is disabled. Otherwise, it can be selected, which looks totally weird.
Mark's example would work. basically you need an adapter with different view types. Another nice example is
http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/
which might work better than Mark's because you want to have separators and group things together.

Categories

Resources