Add footer to an Expandable ListView - android

I have an expandable listView which already has some data(from database). When user opens my application, a "loading" header is displayed during which new data is pulled from the internet.
Now when the new data is received , I store it in a database and update my cursor. New data is displayed above old data.
I also have a footer which asks whether i have to load more data from the internet. Now , the footer is displayed below the old data. I want a view in between the new data and old data, i.e. below new data , so that when clicks on that view , new data is pulled from the internet , which is pushed below new data but above old data. (You can imagine twitter timeline example for understanding my problem.)
How do i implement this ?

I don't know if it will work exactly as you expect, but try MergeAdapter (link below) with added View. You will have one ListView and two same adapters - one for the old and for the new data. Between will be some View - in your case loading Button.
MergeAdapter adapter = new MergeAdapter();;
adapter.addAdapter(oldAdapter);
adapter.addView(loadingLayout);
adapter.addAdapter(newAdapter);
MergeAdapter enables to show (something like) two ListViews in single activity with single ScrollBar. But there is/was some problem with removing added Views. Check it out if this option is enabled.
Link to MergeAdapter: https://github.com/commonsguy/cwac-merge
Maybe this will be in some case helpful: http://pivotallabs.com/users/joe/blog/articles/1759-android-tidbits-6-22-2011-hiding-header-views

Related

ListView with headers (LongListSelector) for Xamarin.Forms

I'm looking for a view known as LongListSelector on the Windows Phone. It's a list view with group headers. Tapping a group header displays only a list of groups. Tapping a group on the list of groups hides the list of groups and scrolls the view to the selected group. It's a very useful way of groupping long lists with easy navigation between groups. If there are alternatives fit for the same purpose that would be also great.
You can do this easily :)
The first thing you need to do is make sure your data source is a collection of collections. I would suggest an ObservableCollection> if you want maximum binding goodness. Then we can construct our listView as follows:
var listView = new ListView ();
listView.SetBinding (ListView.ItemsSourceProperty, "Data");
listView.ItemTemplate = new DataTemplate (typeof (MyCell));
listView.GroupHeaderTemplate = new DataTemplate (typeof (MyHeaderCell));
listView.IsGroupingEnabled = true;
listView.GroupShortNameBinding = new Binding ("Title");
In order, we first bind in our data, I am assuming the BindingContext here will be inherited from the page. Our data should be the collection of collections already mentioned.
Then we bind in our ItemTemplate as normal, we make a GroupHeaderTemplate, this will be the template shown in the list during normal scrolling. Next we enable grouping to tell the list to use the data as a grouped collection rather than a flat list.
Finally with all that done, we provide a binding for the GroupShortName. This binding is run against the collection for each group to grab out a string (or an object that will have ToString called on it) to produce the jump list as you showed in your screenshots.
For performance reasons you may want to ensure the ItemsSource is not set until everything else has been set to avoid the ListView attempting to realizing Cells in a partially configured state. This will not actually result in bugs, it just forces the ListView to do more work.

Save ListView content

I have a Google's NavigationDrawer which adds/replaces fragments. One of fragments has a listView filled with custom BaseAdapter by network request (asyncTask, takes times). What i want is to save listView contents somewhere so if user navigates to another fragment through navigationDrawer and then or later navigates back to the fragment containing listView - i want a listView to be populated immediately with saved old content before asyncTask finished loading new content. Minimum API is 10.
What did i try.
onSaveInstanceState - serialize Parcelable ArrayList<CustomObject>. Somehow i didn't get it working. Also, that isn't solving my problem however, because onSaveInstaceState doesn't triggers on navigating through navigationDrawer.
Setting new fragment's InitialState(setInitialSavedState) then saving(saveFragmentInstanceSate)/loading it. That works for simple Views like EditTexts and TextView, but didn't get it working for the listView.
What is a best way to save listView contents? Please help me.
First get all items of list view.
CustomListViewAdapter listadapter = (CustomListViewAdapter) listview.getAdapter();
ArrayList<CustomObject> object=new ArrayList<CustomObject>();
for(int position=0;position<listadapter.getCount();position++)
object.add(videoadapter.getItem(position));
Now Use the object to store the items of the listview
Then use shared preferences to save the object.
Android ArrayList of custom objects - Save to SharedPreferences - Serializable?
The proper way to do this is to save your network query results in a database (sqlite), and use data from that db to display items in your list (CursorAdapter works best for this).
These tutorials nicely explain how to make your own Content Provider using Sqlite, and use a CursorAdapter to display your data on a list.
http://docs.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/part_4_-_using_cursoradapters/
http://www.vogella.com/tutorials/AndroidSQLite/article.html
I found a good way.
String list_items = ""; // all your items are here, but separate it with a comma (,)
String[] list = list_items.separate(",");
And save the list_items in a shared preference. To retrieve just use getString() and use the code above

Is a new request better than pass parameters by listview in android?

I'm doing a listview in Android that takes the date from a json with some information, I want to know the fastest way to create a new activity with all the data of one item.
What is more efficiently pass and id of the item in the intent and make a new request in the new activity or pass all the data of the new activity in the intent?
I guess that make two requests is worse than make one and pass the data in the intent, but maybe this information is too big to pass in the intent.putextra();
Thank you!
If you have the same information in the Listview that you'll have in the activity, then passing that info should be faster than making another request.
Nevertheless, if you only show a small piece of info in your ListView (which will also make it smoother) and then you show the full item when an element is clicked, then the first aproach is better.
Example:
I have a list with my contacts names and when i select one, i open a new activity requesting and showing all data of that contact.
This will be faster than have all unused info in my ListView.

how to fetch 20 objects at a time from 1000 objects and show in listview

In my application I am fetching the data from a web service in XML format, and parsing it and showing the data in listview. The problem is that if the web service contains 5000 objects then it takes a lot of time to display the data.
Can it be possible to show some data in listview and fetch the data at the same time at the end of the list.
Please provide me some sample code.
If you use convertView in your ListAdapter´s getView method it should not matter how many items you have in the list since the Views are beeing reused.
If your Listadapter takes an array of som sort you could add items to the array continuosly and call
mListAdapter.notifyDataSetChanged();
every time new data is added to the list.
By Using AsyncTask you can do this easily as each object is being fetched can be shown in listview using publishProgress() method while also updating user about what percentage of data hasbeen loaded.
Update:
By the way according to your situation the tool below which is developed by commonsware https://stackoverflow.com/users/115145/commonsware will suits you best...
https://github.com/commonsguy/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.

Problem with list activity

I have implmented pagination and it display 5 records per page. Now suppose I am on page 3 and click 3'rd element then 3'rd element of page-1 is selected.
I am not able to figure out problem as I always create new list object while setting data.
I used below code
temp = new ArrayList();
this.someListAdapter = new SomeListAdapter(this, R.layout.row_facet,temp);
setListAdapter(this.someListAdapter );
Below is signature of SomeListAdapter class.
public class SomeListAdapter extends ArrayAdapter<VoNeighborhood> {
}
Please help....
There really aren't enough details here about how you do pagination with your ListView.
So I might guess you're overriding onListItemClick and using the position variable it sends you, but you then don't take into account the page you're on?
Alternatively, just don't use pagination as you have an infinite canvas to scroll your list within — I don't think I've recall seeing an Android app so far that uses pagination!

Categories

Resources