I want to display the ListView items in alphabetical order.
I also want to display the items with a separator.
If any one knows can you please help me on this? Thanks in advance.
There are two basic ways for ordering your ListView:
Use Collections.sort() and have your objects implement the Comparator interface.
If you are using a Cursor to load your data (e.g. from a ContentProvider or database), you can use the SQL to order the data returned.
As for adding sections to your ListView, there are also 2 basic ways to do this. Both methods are very well documented in this blog post by Cyril Mottier.
Related
Want to achieve this in Android using ListView and data from cursor (result set returned by a database query).
Popular cities are identified by a flag in the database.
Any suggestion, ideas or third party library would be helpful.
You need to make the List View as Indexable. You can check the below link which I used as well to achieve the same.
Complete library source:
https://github.com/woozzu/IndexableListView
Particular class source:
https://github.com/woozzu/IndexableListView/blob/master/src/com/woozzu/android/widget/IndexableListView.java
You can use customized ExpandableListView and show your data in sorted order by alphabetically. You have to take care about both Group view as well Child view.
Just use section indexes! They're built into ListView
Now, I used ListView and ArrayAdapter to show data from sqlite. My old implementation is retrieve from db and set to arrayAdapter. Then set adapter in listview.
But now considering to move to efficient adapter. What if sqlite have thousands of records ? I knew I have to retrieve first 20 records then retrieve next items based on scroll. I wonder Can I get that implementation by using cursor adapter ? Or May I know better solution for that situation.
When having thousands of records in a Database/Server response or whatever you are fetching the information from, the best practice is to do use "Lazy Loading" technique, basically what it does is, showing chunks of data sets to the user for example, 50 elements at the time, so, there's no need to load 950 elements that might not even be used, this technique improves considerably the application response and your memory too, now how you implement it is really up to you, there's a BaseAdapter class to do it on your own, or a good implementation of Cursor/Array adapters might do the trick as well.
Is important to mention that cursors have one advantage:
Cursor lets Android manage resources more efficiently by retrieving
and releasing row and column values on demand.
Hope it helps!
Regards!
First of all, the main reason I use CursorAdapter is that the content will automatically change if the data in sqlite changes. I don't need to consider about refresh UI if something changes below.
Secondly, both the query of sqlite and listview already make some optimization you want. The sqlite will not give all the data on the moment of executing query by default. It uses a slide window to gradually give the query result. And listview also does not draw all the item at once, it draws the items as the user scrolls down.
Hope this helps, though doesn't exactly answer your question
you can involve a thread which retrieve data from database and put into a Map or List. then when you need data like per 20 records when you scroll read from Map. it may help you.
just make another layer between database and view.
I used ListView to display data from database , for example I have three columns and I use new line for each column in the same ListView item ,but I wondered if there is control like data table for android, what do you think the best control to use in this case ?
ListView with a CursorLoader might be you're best option:
http://developer.android.com/guide/topics/ui/layout/listview.html
My team built a table as just a ListView with consistent widget widths across rows.
Could checkout other subclasses of AdapterView, which support the same kind of data loading.
Here is a guide:
http://developer.android.com/guide/topics/ui/binding.html
And the reference:
http://developer.android.com/reference/android/widget/AdapterView.html
Curious if anyone knows something better, maybe a good 3rd party option?
I have what I assumed was a straight forward issue, but after a thorough search I can find no solution:
I have two data sources with two distinct data types: apples and oranges. The only column in common is "datePicked". I want to query the separate databases and then display both apples and oranges in the same list ordered and grouped by "datePicked".
I see some suggestions to use MergeAdapter. However, unless I am missing something, MergeAdapter simply concatenates two Adapters, it doesn't really merge them. Likewise, I have seen suggestions to use MatrixCursor or MergeCursor to create a single unified cursor and then creating an adapter for that. Neither seem a good solution. MergeCursor appears only to concatenate the cursors, while MatrixCursor appears to require that I iterate through both datasets start to finish building a cursor row by row. Even if these were acceptable solutions, I still have the problem that different schema require different layout on the screen. How would I inflate different layout based on underlying data type?
So I am stumped, and would appreciate any help. Is there a true merge adapter that will interleave the data rather than just concatenate it? If not, is there a way to create an Adapter that conditionally maps and inflates a layout based on some business logic done to the specific row being pointed at by the cursor?
Sorry if I am missing something obvious.
Thanks,
To answer my own question, it appears that building a Matrix cursor with a merge-sorted-list type algorithm stepping through both cursors, and then conditionally inflating a row layout by overriding the newView() method with an if statement is the only workable solution. I will post the code for anyone who is interested once I've worked out the details.
I want to do a listview on android and it contains an alphabet near of the list (like iphone application).
I couldnt find any way to implement an list and having alphabets, when ı click on c letter list scrolling and start with the c Letter.
Thanks
May be FastScroll fits to you?
http://developer.android.com/reference/android/widget/AbsListView.html#setFastScrollEnabled%28boolean%29
You can get it by using Database,manage a table to store parsed data and then display data in listview by fetching it database table,
please refer the link for more about database in android
http://developer.android.com/guide/topics/providers/content-providers.html
I tried to do the same and i ended up putting a list view and a textview into a frame layout and then using touch positions in conjunction with list.setslection() to focus...worked for me ! more here: Replication of Apple's Search in Android
I agree with Sergey Glotov, regarding Fastscroll, please take a look at sectionIndexer interface.
Maybe these links(eg1 and eg2) will help you.