Load list items on demand - android

I would like to load a list of messages on demand.
I show 20 messages on my listview and when the user scrolls on top of list there is a button to load more 20 messages.
Like whatsapp, when user clicks on the button, more messages are loaded above and the user can scroll 20 more messages.
I have tried to make it with Loaders, every time the button is clicked I publish an event that load messages on the adapter.
However when the adapter is releoaded with new itens the focus goes to end of list.
I have tried to set the focus to the right positon, but the Loader's events reload the adapter and the focus come back to end of list.
The only solution I found was to set the focus after a time, but the user can see the list going to end and coming back to the right postion.
How can I load messages on demand like Whats app?

You have to add only 20 objects in your ArrayList and add HeaderView in your list adapter .On click on headerView .It will load more 20 items in your list adapter . and call notifyDataSetChange(); afterwards.

Related

listview setOnItemClickListener not working on some items after refreshing the list items or leaving activity open for some time

In my activity, list view having multiple items populated, based on canceled, approved or rejected i am differentiating them.
list.setOnItemClickListener on every items works perfectly till i am refreshing the list(refresh method that updates the list items) items by refresh button.
After refreshing or leaving the Activity idle for some minutes onClick event on approved items doesn't seem to be working and i am unable to figure out the reason behind it.
Any suggestion will be much appreciated.

how to maintain data consistency in listview

I have a app that displays data in a listview using baseadapter. The user is able to click a element in the listview and it takes the user to a page where they can edit the data that is being displayed on that element. When the user clicks back it takes the user to the listview however the changes are not updated. How can i update the listview once the user clicks back.
I think just set your adapter in onResume() method, so each and everytime you should go to on that screen, each and everytime it will refresh your Adapter.

How to avoid Tap to Refresh

I am using:
https://github.com/johannilsson/android-pulltorefresh
To get pull to refresh.
The problem is when I open the ListView for the 1st time, it shows a top header saying:
Tap to Refresh
When I do that it shows
Loading
and gets hidden. Then after everything works fine.
How to avoid showing that initial Tap to Refresh header and just show my ListView with Pull functionality alone
Issue here is when ListView don't have sufficient items to scroll it shows TAP TO REFRESH text when ListView has sufficient items that text gets hide so your issue is your list don't have many items at first time...

Android - ListView event when user reaches 50º list item

I want to set a simple listener in a ListView so when the user passes through the 50º item of the list, I call a thread that will append 100 more items into that list.
I am looking for an event to do that for over an hour now and I don't seem to be able to find one. There are tons of events for when a list item will be clicked or something like that, but I can't find one for when the user simples passes through the item in the scroll processing.
Thank you so much in advance!
Put the ScrollListener on list view, when it reaches end of the list u will get the last item, then add the progressbar at the footer and then start thread where u can load the other items, and notifyDataSetChanged() for adapter , and you will get the list with added items..!!
And you can check whether the item number 50 is reached, in onScroll().
I think there is no need to do this, because the ListView recycles the item views. So you dont occupy memory for the listview items (per each value), you just use memory for the ArrayList(or any data type you use for feeding).
Also you can do this whenever user reaches the end of the listview (last listview item) then refeed the adapter with the new value and then call .notifyDataSetChanged().
About reaching 50% of listview visible items can make things scrambled because you'll always have the 50% reached, otherwise you can improvise (reaching 50% on the ArrayList instead ListView) by checking if more than 50% of the existing ArrayList is displayed, let's say you 10 items and the 6th item is on the listview count / 2, you check if the on that half listview item is more than 50% of data feed for the listview you feed with new data. (I might be unclear)
I hope the idea will help you.

Unable to update the listView in Android

I have a ListView which displays 5 listitems. When the user selects the last item (5th item), a hit goes to server and the next set of 5 items is displayed.
I have implemented the code for displaying the first 5 items. I am also able to fetch the next set of items from the server, but the items are not updated in the ListView.
If required I can share the sample code.
Kindly provide hints/sample source code.
Did you try clearing the list items first and then update the list elements?
In order to commit the updates you should call notifyDataSetChanged() ..

Categories

Resources