What is the best way to display data from database android ? - 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?

Related

Displaying unknown amount of data to screen

I have a sqlite database which contains multiple messages.
Each message has a
Title
Body
Importance level (0/1/2)
Possible calander _id
I want to display them to the screen in a scrollable list. Each list item can be clicked on which will then start another activity to edit the message.
I don't want direct code on how to do it, I'd prefer suggestions on how to do it so I can learn myself. If I need to give any extra info please ask.
You need to use adapter in your case CursorAdapter would be appropriate. There are many tutorials on internet about CursorAdapter and using it alongside with SQLite:
http://www.vogella.com/tutorials/AndroidSQLite/article.html
https://coderwall.com/p/fmavhg/android-cursoradapter-with-custom-layout-and-how-to-use-it
A general note about Adapters is that they are a mean to transfer your data to appropriate View so you can populate your ListView, GridView, ... with the customized data. But this need a whole tutorial. You can also look to see how to work with different type of views which allow to be populated with Adapters.

Android listview with nested CursorAdapters?

I am trying to implement a variation on a fairly simple Master-Detail view, but can't seem to find anything out there that relates to my particular issue. It's possible and probably that I just am not searching on the right terms, in which case, I'd appreciate a point in the right direction.
Instead of the standard Master-Detail approach that I was originally planning on, I'd like to display the detail in the master Listview as a TextView with ellipsis, and then just display a popup dialog.
For any record in the master table, there will be 1...n detail records, which I need access to when displaying the master ListView.
I've looked at CursorJoiner, but don't think it fits my needs, as it would require the cursors be sorted on the record ID, but for display I want them ordered alphabetically.
Is it possible and a good idea to nest CursorAdapters? In the master CursorAdapter, I could have a new CursorLoader that would load the details for that item. Or is there a better way to go about this?

Need to make a table: which is better for performances?

In my app I download from the net some data I need to arrange in a table way.
I already know dimensions: about 26 rows and 6 columns, anyway data can change across subsequent calls so I have to create this table in a dynamic way.
As it is a table I though using a TableLayout (never used before), on the other hand I could simply use a list view, using for the single item a 6 elements linear layout with horizontal orientation.
ListView intrigues me because it is an adapter view (I think I'll store this data in a sqllite db, later) so populating it is quite simple and straightforward, anyway I don't know if it is the best for my problem.
What is your opinion?TableLayout, ListView or other?
When it comes to performance, I think you should use ListView because ListView support Recycling of view and you can check this and this post for more detail regarding Recycling of view.
Hope it helps :)
A ListView is a collection of layouts that are automatically displayed one below the other. The developer adds new items through a piece of code in the Activity. An example is the address book where you have lots of contacts one after the other.
A TableView on the other hand is defined in the layout file and does not only need to contain elements below or above each other but can also arrange elements on the left or on the right. A TableView is exactly what it says: A table with rows and columns.
here's a similar question that might answer what you want to know

Is it more efficient to load data to a listview from SQLite or create listviews from an array?

Hey guys I was just wondering about some efficiency issues. I am creating an app for android that has a few listviews, some listviews have 50+ items. Basically click one item on one listview will open up another listview that displays more options and so forth.
My question is right now I have these listviews populated from arrays but would it be more efficient to create a database and pull data to populate these listviews?
If this question has been asked already I apologize I have searched but have not found what I was looking for.
Beside of choosing between arrays or sql as datasource, is important to analyze the complexity of your view; sometimes is important "load views on demand" you may want consider this best-practices for optimization of your app: https://developer.android.com/training/improving-layouts/index.html and this https://developer.android.com/training/improving-layouts/smooth-scrolling.html
Best.-
If list data is not dynamic, I feel string arrays are best otherwise database is best option. database calls are always costly in terms of time/resources.
It depends on your data, if your data doesn't change , you can define them in xml file under ./value/. And sqlite just like other database, and it cost another I/O operations and it will reduce efficiency. But I think it doesn't cost too much in an android app.

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

Categories

Resources