Adding from 2 databases to a listView row - android

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.

Related

Android most efficient Table Layout

So I have a few arrays of data I would like to display in an activity without having like 15 text views with unique ids. Is there a code efficient way to make a Table layout or something like it where I could feed in data and it would automatically place it in there respective text views? Thanks!
I think you can achieve that by using RecyclerView (with a GridLayoutManager). Have a look at this answer.
If there are only TextViews and you don't want a specific layout you can use SimpleAdapter, if you want to modify the layout you have to extend RecycleView.Adapter (there is an example in the answer above).
You can add/remove items into/from a List and use DiffUtil that
can calculate the difference between two lists and output a list of update operations that converts the first list into the second one.
There are a lot of tutorials about using this class. Have a look here or here.
Or you can use the notifyItemChanged() method:
If the list needs an update, call a notification method on the
RecyclerView.Adapter object, such as notifyItemChanged(). The layout
manager then rebinds any affected view holders, allowing their data to
be updated.
LE: There are some libraries available. Here is a list:
https://github.com/evrencoskun/TableView
https://github.com/HYY-yu/TableRecyclerView
https://github.com/Cleveroad/AdaptiveTableLayout
https://github.com/celerysoft/TableFixHeaders

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 spinner from sqlite - best method?

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);

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.

Categories

Resources