I am programming for android 4.0
I would like to create a listFragment divided in 2 sections. This means i want it to be 1 long scrollable list but with a divider between the online items and the offline items. And of course when one item comes online it should jump upwards + the other way around.
All the items are clickable but the divider shouldn't be (and preferably have a differend colour)
How can i do this or is this even possible?
Ok so , a fragment is basically an activity and you can treat it like an activity, in your case you should extend ListFragment (which will act like a ListActivity in a sense).
now, a List Adapter (which populate a list) in its default way will only allow you to display a list in its most simple form so in order to achieve what you want (a list that deals certain list items differently) you will need to write your own Adapter.
its best if you get the data in the order you want them to be displayed so if you can sort the "online" items from the "offline" items straight from your data source you should query it this way. so now the only thing you need to add is a separator between them and you can do it by finding the first "offline" item and inflating a separator above it (this is done inside your adapter).
each task by its own has dozens of tutorials and Q&As around the web and on StackOverflow.
hope it helps and i'm here if you need more help.
Related
In most case, we need to implement the BaseAdapter’s getItemViewType() and getViewTypeCount() for dynamic item content of the listview, as this post says. But I think this solution is only suitable for finite number and knowing beforehand, such as listview item with sending layout and receving layout.
What about the case that the listview with its item content impossible knowing beforehand?
For example, I need to show a contact list from server, the contact list size is about several thousand. For each item, I need to show, for example, the hobby “list”. It is a small range of 0 to tens of string. So in this case:
The item types is relatively bigger than normal case using “getItemViewType”
Though each item may be different, but similar to a certain degree: the item content is different in the number of views, but common in view type. Item A is different from item B only because it have more TextViews.
For each time in the getView, the convertview is hard to simply reuse because they are different, but if we create new TextView and added to the convertView, it will impact the scrolling of the listview. I don't think it's appropriate such way. What should i do in such case?
Unfortunately you cannot easily change the number of item view types on the fly. The getViewTypeCount() method is only invoked when the adapter is set on the ListView. That means, were you to dynamically change it, then you would have to call setAdapter() again. This is a huge performance hit as the ListView will toss out all the recycled views and re-generate everything from scratch again.
Honestly, it looks like you should be using an ExpandableListView instead. It allows you to displays lists of items under groups. The only difference is the groups are placed on top of the list. So where you have A, B, C, D on the left side in your picture...in the ExpandableListView it'll sit on top.
The ExpandableListView can easily handle your situation where a given grouping could have any variable number of items within it. You mentioned needing to store a contact list. I'd suggest taking a look at a RolodexArrayAdapter for use with the ExpandableListView. It may be of help.
I want to know that what will be the best way to implement spinner in a listview. My scenario is I am getting products names, prices and their number from server side. For this I am going to make one main Activity (with one xml) that will contain the listview and a separate adapter class to make the adapter for the listview and that adapter layout. Now I want to ask is this approach will be good as I will be having some operations on spinner selection (getting each spinner (or product) dropdown number, spinner (or product) name and position) and also I will have to handle spinner positions as getview() will render each time? Or you people suggest me some good ideas instead of this?
Having many spinners in a ListView is possible but I would imagine in most cases it'd be inconvenient for the user -- too much clutter and moving elements on top of each other. I suggest you create a separate Fragment for item details, and only display static items in your ListView that will take the user to item details fragment (with spinners and anything else you might need). Take a look at this design pattern: Multi-pane layouts
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.
I am making an application and I can't figure out what's best to do.
I have a long list of tableRows. About 200 of them. They are different
models of a specific product. Each row, when clicked, should show a
screen with that item's specs for the user to read.
Here are my options, I would need help and guidance on how to do each one of these as I am a beginner (but I'm getting more advanced)
First Approach
Create an activity for each and every item. The user will click the row and then they will have to press back to get back to the list. (I know how to do this. I'm fine with this)
Second Approach
I read about horizontal page swiping. Similar to the Play Store. I would prefer this option, but would I be safer sticking to lots of activities?
When the user clicks a row, it would bring them to the item spec and they will be able to swipe left and right between all the items. Pressing back will bring them back to the list.
(This is the one I need full step-by-step guidance with, so I can learn for the future, thanks)
Does anyone have any other suggestions how I would handle this amount of data?
Thanks
You have a long list of items. That suggests you use a ListActivity to show the items. If the items have similarities, use one view to show them and one Activity to show details. If the items are totally different, use different layouts to inflate in getView and different activities. Having the items in one list suggests, however, that there are similarities and it's best to use one layout in the listview and one activity for details.
Alternatively, you can group your items according to similarity in the way you show them. You may end up with ten different views to use in the listview, and ten different activities.
I currently have one long ListView in my android application and I would like to separate that one ListView into multiple pages so that when the user selects the next button, that will be in the actionbar, it goes to the next set of ListView items.
How do I go about achieving this?
You can write your own ListAdapter/ArrayAdapter and have it only load the items you want to. The arrayadapter is good and easy enough to use.
ArrayAdapter example,
here is another example