Android spinner from sqlite - best method? - android

So at the moment I have a simple reminder app that you enter some details, select a data and time and then the app reminds you on the selected date/time.
I now want to be able to add functionality to select categories which I want to select from a spinner, which is populated from separate database table - I will be adding a class to add new categories.
Is an sqlite database the best way of doing this or is there an easier alternative? I assume I will need to make foreign keys/triggers?
Any advice is much appreciated.

Yes, I think the best way is to use sqlite3, especially if you're mutating data.
Spinner is an AdapterView like ListView or GridView, so you can just use a CursorAdapter (or possibly SimpleCursorAdapter) to populate it with data from your database.
This looks like a decent tutorial for creating a SimpleCursorAdapter. In your own code you would call spinner.setAdapter(mySimpleCursorAdapter);

Related

What is the best way to display data from database android ?

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?

What is the most efficient way to populate a listview?

I have an app which mains view is a listview. Each item consist of multiple textviews and imageviews. Now, what is the most efficient way to populate these items? String arrays? External text file? Online text files?
for example this is an item in the listview:
The listview will contain over 50 items and these items will increase every week. So it should be as easy as possible to add new items!
First of all you pick an efficient way that works for YOUR project.
I would recommend just using an SQLite database for such.
You could use Text files, but you have a database availible for such, so i would recommend using it.
Here is more info on SQLite and how to get started using it.
EDIT:
Also you could possibly use online text files. And just read the information from them. This may take some time when populating the list, so i would recommend doing this in he background, and trying to write the information to a abase.
Using SQLite and getting started

Android Complex View: manually create or using layout xml file?

I need to create an activity(view) that shows several lists, for example:
(text)Fruits:
(item)apple
(item)orange
(item)pear
(text)Veges:
(item)Cabbage
(item)Carrot
all data are read from a database, so I cannot determine them and create layout file(xml) for them, what's is the best way to create this? Also, list items are clickable which directs users to another screen.
Thanks!
ListViews are filled with data using Adapters. So, you can use a single layout with a ListView and change adapters depending on what you want to display.
Have a look at Adapter interface.
And if you want to have several ListViews, then in your case I'd use a single ExpandableListView widget with differet groups like Fruits, Veges and so on.
If you have created a database using sqlite already, U can use cursor adapter to fetch the data from your database. Its really simple. try to find out how to fetch data from database and how to insert values into listview using cursor adapter.

Android tabluar data from database

I want to show all the data from the database in a View. addview to the layout is a good idea. But as I don't know the no. of data, I cann't create required no. of textview, and i cann't add a single textview multiple number of time. How can I solve this problem?
But as I don't know the no. of data, I cann't create required no. of textview, and i cann't add a single textview multiple number of time.
You don't need to create TextView multiple times, it would lead to more complex application.
Rather I would suggest you shold create a simple or custom ListView using simple or custom ArrayAdapter or BaseAdapter or CursorAdapteraccordingly your needs.
Refer this: Getting Stored Data from my Database into ListView
Just read this article to learn how to get info from the database using CRUD methodology:
http://knightswhocode.com/wordpress/?p=14
Create a list of items taken from the database. Then create a ListView with adapter using this list.

Adding from 2 databases to a listView row

Can I add data 2 from different databases into each row of a ListView in Android?
I have a vendor app and I want to add data from one standard items list table and one daily table to the list view.
Yes, but you won't be able to use the CursorAdapters implementation easily. I would put all data you need inside an array, and then you can write your own BaseAdapter or use an implementation of ArrayAdapter.
You might also want to checkout Commonswares CWAC-MergeAdapter maybe it is of use for your problem. It is meant to provide you an easy way of handling multiple data sources and views for display in one ListView.

Categories

Resources