Android: ListView, Last item - Show more - android

I have an issues, I want to show 20 items in the list.
But there is a catch: if the user scrolls down to the bottom of the list, there will be an item that says: "Show more items", and when the users click on it, more items will be added to the list.
My question is how is poosible to have a last item, that has a different style and looks different: and does different things,(I think this is used in QuickSearchbox)

If you still want a clickable item rather than an infinitely scrolling list you can try using ListView#addFooterView to add your "Show more items" item. This lets you add a view as the last item in a list. Make sure you call it before calling setAdapter.

I would recommend you commonsware's cwac-endless.
cwac-endless: Provides the
EndlessAdapter, a wrapper for an
existing ListAdapter that adds
"endless list" capability. When the
user scrolls to the bottom of the
list, if there is more data for this
list to be retrieved, your code gets
invoked in a background thread to
fetch the new rows, which then get
seamlessly attached to the bottom of
the list.

While commonware has some awesome stuff. His endless lib may not be what you want. What you probably want is a footer. On your ListView, before you set your adapter, call addFooterView. Note that if you do that, the adapter you get from ListView.getAdapter will not be the same as what you passed to ListView.setAdapter.
Edit
Speaking of commonware, he sells a few books on his site. Buy them. They are the best $40 you will spend on your android education.

In the layout below the listview you can put a linear layout with "Clear" and "Get More Results" buttons. Not exactly what you are asking but it can achieve the same result.

Related

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.

Access Adapter items of Recyclerview

I'm using Recyclerview to show a list. I want to delete some items like IOS. In my listview template I have added a button to delete item which is invisible by default. In my activity I have another button attached at bottom (Not part of listview) and on tap of this button I want to make all delete buttons of listview visible.
My Question is how can I get reference to all delete buttons of listview in activity and is it the right way to do this?
Thanks
Assuming you have ViewHolders set up, you already have references to all the buttons in your list. All you have to do is to make them visible for every item in the list with a simple loop.
In case you haven't implemented ViewHolders I suggest you check out the documentation and take a look at some simple tutorials on how to use them.
On a side note. If I understood correctly you're making a bottom tab for your app and since you referenced iOS I gotta say this; Remember that Android and iOS are two unique operating systems with their own ways of handling things. Check out Googles pure Android documentation.
In your question title you say RecyclerView, but in your text you say ListView. The solution is similar either way, but it's best to be perfectly clear what you're doing.
In either case, there are at least two different solutions.
First, you could use a boolean flag to determine if all the the item buttons should be showing or not. You check this flag at the time the item view is inflated or created and toggle the button accordingly. If the boolean flag is ever changed, the easiest thing to do is tell the RecyclerView/ListView that the underlying data has changed and to redraw all the views. Call notifyDatasetChanged on the adapter.
The other thing you can do at the time the item buttons should change is iterate all the visible item views, find the button, and change its visibility. With RecyclerView, you can do this, and with ListView you can do this.

Android ListView with headers and swipes

I am working on a shopping list app, and in one activity I need show many shopping list that I want use expandable/collapsible headers. Also, I want to strike out item by left swipe and delete item by right swipe.
I am looking for some ListView that can do this.
I tried to use StickyListHeaders lib with swipe layout but it works incorrectly (white spaces after deleting).
Anybody can help me?
Maybe you need to update your adapter content and call notifyDataSetChanged() to refresh your data and remove the empty space.

Listfragment divided into sections

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.

Android - ListView with only 1 expandable item

I have a listview with tickboxes, which uses an Adapter and which works well.
And I know how to make a whole list expandable.
But, it it possible to have just a single item expandable, or does it have to be the whole list?? If so, how is it done?
You would need to use Lists of one item each. Unfortunately there is no SDK widget that handles the special case you need.
You can insert (or remove) the 'child' items in the right place within your adapter's data set when the 'parent' is clicked using a normal ListView.
You could actually use an ExpandableListView and think of the non expandable items as group item with no child.
That's the way I have done it. I have my own adapter which handles showing/hiding the indicator depending on whether the group item has children or not.

Categories

Resources