I'm trying to implement the above mentioned. From this link, http://www.pocketmagic.net/?p=1870 , it pretty much shows what I'm trying to achieve, except I want to show an icon on the left side of the contact based on a condition. i.e. If Aaron is in Company A show Company A icon, if Betty is in Company B show Company B icon. Problem is the contacts data is from 1 cursor and the company data is from another cursor.
I'm looking at a custom cursor adapter, is there a way to create a single cursor with data from 2 cursors and set it into the list adapter? How this makes sense. Thanks!
This can only be done if you extend the cursor adapter and then INTERCEPT the data when its building the views and build it how you want it with the cursor data that will be coming in. Once you have this setup its pretty easy. And there is a cursor that can take two cursors and put them together.. but I can't remember if this was custom or not.
Simple way is to just take the data and throw it into a datastructure and then handle it from there. Also there is no rule saying you can't pass in two cursor into your cursor adapter. MAKE IT YOURS! :)
I just answered a similar question to this that was to use an ArrayAdapter of an Object list. Take a look at the code I posted and instead of extending ArrayAdapter, extend CursorAdapter (If you need to use a Cursor). Or you can build up a Custom Object and use the ArrayAdapter approach
How to put query of information into a listview?
Also, here's the reference for a CursorAdapter:
http://developer.android.com/reference/android/widget/CursorAdapter.html
Hope this helps!
Related
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.
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.
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);
Wow... that is a pretty long title. But here's the gist of my question.
I return a cursor that contains data from an SQLiteDatabase table called Budget. One of the columns in the database stores the currency amount for an item.
The table looks something like this.
_id Item Amount
1 Book 299.99
Right, so I return the cursor, make use of my own custom adapter which inherits from SimpleCursorTreeAdapter and then load the data into an ExpandableListView.
Now the question is, how do I go about formatting how the Amount is displayed. I know how to do the actual formatting (NumberFormat to local currency), but I want to know how to gain access to the cursor's value to modify it, before it pushes into the ExpandableListView.
Do I access the cursor or should I be dabbling in the SimpleCursorTreeAdapter methods?
I would appreciate any advice and direction as I'm completely stumped on this one.
Right, so after much digging, with trial and error the solution is pretty simple.
If you are using API5 and up, you can just use a ViewBinder to customise your output.
If you are using API4 and up, you can't use a ViewBinder, so you'll have to override the bindChildView method of your custom adapter.
Hope that helps someone.
I have a ListActivity that's populated with a SimpleCursorAdapter which pulls the data from a database. I want to set images on the rows at runtime based on the data in the database. If the data is a one, I want a filled-in icon, and if it is 0, I want it to be hollow.
In order to do this, I figured it would be easiest to access the layout of each row individually, and change the image, but I can't figure out how to access the individual rows without clicking on them.
I also eventually want the image itself to have a separate click event from the row it's on, but I'll probably ask another question for that.
While 100rabh's link did help me construct better searches which helped me answer the question, the answer I needed was that I needed to build my own custom cursorAdapter which I just extended from SimpleCursorAdapter.
The setViewImage(ImageView v, String value) method helped, although I also did a bit of customization on bindImage to handle all of my cases for the various lists I used this for.