android ListView subitem database - android

I'm making an application with a database of courses (of school) that the user is participating in. I want to display those courses in a list (im using listview) and use also the subitem (extra information of that course) of the listitems. I found a tutorial (http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/) that displays a list like I want but it uses a class to store the data in instead of a database. So the tutorial uses an arraylist of objects of that class. It would be a detour though if i had to put my information from my database into a class to put it in the list.
Does anyone have a clue how to solve this?
Thanks!

I found a beter way. By using a simple adapter and putting the values of the cursor in a hashmap in a arraylist. Found the idea from this site: http://eureka.ykyuen.info/2010/01/03/android-simple-listview-using-simpleadapter/

Here is a perfect tutorial for what you need. It shows you how to create a simple SQLite database and then populate a listview using the database.
SQLite Database creation and Listview Population Tutorial

Related

Populating a Android ListView with MySQL data

I want to retrieve data from a MySQL database and populate a ListView in my Android application. I've seen answers on stackoverflow that use complicated methods of retrieving the data from a MySQL database using JSON objects. Instead, is there anyway I can use something similar to a MySqliteCursor to connect to a MySQL database? Is the Cursor Android class limited to using SQLite databases? If none of these options are possible, is there an easier way to populate a ListView with MySQL data?
See CursorAdapter class. It receive cursor, db column indicies and ids of widgets of view. Then it take data from db and populate corresponding fields
Yes, it receive Cursor from sqlite. You can easily implement adapter for any data- just know number of rows and query row under particular index. See RecyclerView tutorial (updated listview)

Update ListView based on SQLite backed ContentProvider

I'm a new Android Developer and seem to have gotten in a little over my head. I am trying to make a listView update when I add more content to the list.
The ListView is based off of a SQLite database. I was able to get the ListView to be based on the SQLite database by making a ContentProvider for the SQLite database (which was suggested here). Now my issue is that I want to update the SQLite database and have it reflected on the ListView. I am using a loader and according to this if I implemented the loader right it will monitor the data.
I tried updating the SQLite database directly but, that didn't cause the ListView to update without closing and reopening. My instinct from there is that I should implement the insert method in my contentProvider. I did a very simple implementation:
#Override
public Uri insert(Uri uri, ContentValues contentValues) {
return ContentUris.withAppendedId(uri, mCollectionDB.insertCollection(contentValues));
}
Unfortunately, the result of this is my app crashes with a "java.lang.NullPointerException". This is especially confusing as using the exact same contentValues to make the .insertCollection call from my MainActivity works without issue.
The issue I'm really interested in is how to get my listView to update when I insert data into my SQLite database. If inserting into the ContentProvider is irrelevant then please ignore that. I'm not really sure where I went wrong so I'm not sure what other code may be useful, but I'm happy to edit in more code if it'll help.
You can check loader concept.
You can start with
http://www.vogella.com/articles/AndroidSQLite/article.html#todo
Following are other 2 good tutorials
http://mobile.tutsplus.com/tutorials/android/android-sdk_content-providers/
http://mobile.tutsplus.com/tutorials/android/android-sdk_loading-data_cursorloader/
Hey here is one example to insert data into sqlite database and display it in list view.
Have a look at it
The idea is simple insert data into database and on click of view button initialize List view with arraylist that contains data already inserted.
You can ask if you have any further queries.

CursorAdapter vs ArrayAdapter for a ListView

I want to fill my ListView with data that's going to come from the web in the form of JSON. The list should be theoretically infinite, with the app making requests for more data if scrolled to the bottom.
Should I use a Cursor or an Array(List) adapter to link my online database with my ListView?
More generally, what are the arguments to consider when choosing between cursor and array?
Well I think you should look at ContentProviders. They are more natural to the problem that you are trying to solve. You have to implement your custom Cursor which ContentProvider returns on a query request.
Ref:
http://developer.android.com/guide/topics/providers/content-providers.html

Retrieving Database Information and Showing in ListView with Android

I am working on an Android app that will allow the user to see restaurants in the city I live in. I am storing each restaurants information (name, address, telephone, hours, category, website) in an SQLite database.
What I am trying to do is to create a SortByAlpha activity that will list the restaurants by name in alphetically-descending order.
I understand that I should be using a Cursor to do this but I can't find a half decent tutorial, all of the "tutorials" I find are a bunch of code with minimal explanation. How can I do this / Where can I find a good tutorial?
Use SimpleCursorAdapter, which bridges between Cursor and Adapter. Here is an example how to use it: http://developer.android.com/guide/topics/ui/binding.html
I would advise creating a "Restaurant" class that contains all the fields you will be listing. Then make your SQL call and specify "ORDER BY Name". Then create an ArrayList that can be fed to your custom list adapter! Also, if they were to somehow get out of order, just implement the "Comparable" interface for the Restaurant class and compare based on "Name" and then you can call Collections.sort(restaurantlist); to sort them in alphabetical order. I personally think ORDER BY is the easier way to go!

Autocomplete list from SQLite with criteria

Can someone point me to right direction, how to create an adapter for AutoCompleteTextView, which would be getting data from SQLite DB, using data, which user entered into the text field? I want to use the user-entered data to filter suggestions for autocompletion. I imagine that adapter should always take user-entered data as soon as changes appears and use it for fetching suggestions on-the-fly. Is that possible? So far I've seen many tutorials for autocompletion where static String arrays were used, but never seen them build dynamically. Is it possible to do it automatically or I need always fetch String array myself and pass as ArrayList to adapter on every AutoCompleteTextView change?
You might be looking for CursorAdapter. Use it just like an ArrayAdapter, but instead of feeding it with an ArrayList, provide a database Cursor. Google for CursorAdapter and you should get a lot more example codes.

Categories

Resources