Displaying unknown amount of data to screen - android

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.

Related

how i get the contact list in multiselect or checklist view?

i need to know how list the contacts of phonebook in a check box list to select more than 1 contact at the same time, because i need it to take the checked phone numbers and send to a multi-contact list sms message
This is a very broad/long question. I've done this for one of my applications, so I can outline the steps for you and give you pointers.
Getting the Phone Numbers
You'll need to interact with the Contacts API. More specifically, ContactsContract.
http://dev.schmid.pro/android/get-contacts-on-android-2-0
How to read contacts on Android 2.0
It's probably best to put the data in an ArrayList.
Displaying
You can use a multi-select listview, which is fairly easy to implement
Or
If you are set on creating a listview with checkboxes, you'll have to create a custom adapter so that you can control the clicking of the checkbox, textview, entire row, etc.
http://windrealm.org/tutorials/android/listview-with-checkboxes-without-listactivity.php
Custom adapters are more complex than using the ListView, however, they are powerful and useful and I'd suggest learning them anyways.
You don't need a check box list, but a List View with proper setting.
if you set the choiceMode to either multipleChoice or multipleChoiceModal (3.0+) it automatically render the lists items with a check box on right. User getCheckedItemPositions() to access the checked items.

Calling a custom dialog from a database?

Following on from this question:
ideal database field for calling data to
I have realised that I might be able to simplify my need for information to be brought to the screen by using a Dialog or a Custom Dialog, and by one of these methods I may call the whole finished page from a database instead of using static strings into the layout filling in specific fields with data like I am currently.
There could be a few hundred items or pieces of data to be called up in my App So am I correct with this assumption or do I need a specific other method to acheive this?
I am looking to call a custom dailog from a database so I can call a whole page of information complete but am unsure of limitations on this data wise or even if my sqlite database manager is even good enough for this task, each page will be called up "complete" where as before I was trying to have a template with the unchanging data (coke pepsi etc.)already included and appearing on every "result" page and then blank fields populated with data retrieved from a sqlite database (Litres size etc...) I am unsure which path to take : either make the page complete including all data like an image Or do I stick with my original plan to have a template screen with unchanging fields already in place and the changing information to be populated as needed from a Sqlite Database? hope this makes sense sorry if I was too vague with my question originally Im still learning.
Your question is vague but I'll risk an answer:
If you want to make a dialog like the image you posted on your previous question then this is the way to do it:
Create a custom dialog that will have as content a LinearLayout(with 3 TextViews representing the header labels in your image: COMPONENT, TYPE and AMOUNT, this will be somewhat identical to the list row layout below) + a ListView where the actual data will be shown.
Create a layout file for your ListView row to use(like the LinearLayout above will contain 3 TextViews for the drink name, type number and amount number).
When the dialog needs to be shown just get from the database all the drinks names, types and amounts and bind it to the ListView with one of the adapters based on a Cursor(like a SimpleCursorAdapter)
Getting the values from the database and binding them to many TextViews is not recommended(If you have many(I saw few hundred items or pieces of data)), also your dialog could be called a lot of times by the user in a short period of time and you don't want to do this binding each time for many views.
either make the page complete including all data like an image
Please don't do this!

Loading sub-records for each item in listview

I'm making an app in which the user can log simple timesheet-like transactions into a list. I have done this with a listview which is connected to a sqlite query with a custom CursorAdapter descendent. So far it is working well.
What I am trying to do next is let the user add any number of "tags" to an individual transcation (think labels against emails in gmail). I have a many-many-relationship table to link tags to transactions, but i'm unsure how to modify my existing listview and cursor arrangement so that each individual record can load and display its tags.
One thing that comes to mind is to load all the data into a two-tiered object structure, then use that as the datasource for the listview. I don't like this idea though because it will certainly cause a delay in loading, whereas using a CursorAdapter seems to be better for performance.
The way I was intending to display the tags within each listview item was just as plain text, linearly along the bottom of the row with different colours using Html.fromHtml(). I already have this part working so i was hoping to stick with the existing listview (if possible). My problem is purely about finding the best and most efficient way of getting the tags out of the DB and making them available to each row in the listview.
I'm very new to android - is there a clever way to do this or is it going to be a manual exercise?
There's no shortcut for this. You're going to have to create a View by subclassing LinearLayout, RelativeLayout or whatever you want. In your View class expose a public method like 'setTag(tag)' which takes an argument as to what tag to set the corresponding data to. In your View you'll have to have some field which maintains a reference to that View. In other words, somewhere before you return your view in getView in your Adapter, you can bind the data to the View and then alter its state from within the View.

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.

How to setup a ListView that get its data from a server

I've been trying to find a tutorial of how to create a ListView that get its data from a server dynamically as it's scrolled. I have not been able to find complete documents of how to do this. Only small examples or ListView tutorials that deals with set arrays. This has left me where I don't know where to start building the ListView code.
I have some code that gets data from the server. I also do have all the layouts and basic Activity code.
How/what do ListView do to get one more rows as it is scrolled?
And when I need to have different row layouts. How do ListView handles this?
Is there a complete tutorial that deals with ListView and getting data from a server?
How/what do ListView do to get one more rows as it is scrolled?
There is nothing built into Android for this. You could use my EndlessAdapter, either directly or as an idea of how to accomplish similar ends in your own code.
And when I need to have different row layouts. How do ListView handles this?
You need to implement an appropriate ListAdapter, one that has proper implementations of getViewTypeCount() and getItemViewType().
Is there a complete tutorial that deals with ListView and getting data from a server?
Along with your other two bullets? Probably not. Your requirements are individually uncommon and are even less common in conjunction.

Categories

Resources