This is my current adapter.
This is what i tried to convert the date.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I started changing your adapter to a CursorAdapter but honestly it would be the same as this SimpleCursorAdapter example (I updated it to reflect your code as best I could.):
Ok, all your need to make this work is a method that returns a Cursor with all of the names (I called it
getAllNames()) in your Database class. Now I assumed your table schema looks something like this:You can adjust accordingly. Your
Database.getAllNames()method should use a query like this:Or if you want the names alphabetized:
All together it will look like:
I hope that explains a few things, honestly this is the easiest way to do what you want.
Adding your own row (list item) layout
Adding your own layout is simple enough. Since you like the look of simple_list_item_checked.xml, let’s copy it’s layout and tweak it for your colors:
All you need to add is:
(Notice that since there is only one element a ViewGroup is not necessary; no LinearLayout, no RelativeLayout, etc. Also
"@android:id/text1"is the id that we referenced in the SimpleCursorAdapter `android.R.id.text1′, when you change layouts you need to change these appropriately.)However if you only want to invert the colors consider using a different Theme for you entire app. Open up your Manifest and add this theme:
By default Android uses Theme.Dark, simply change it to Theme.Light. Now every item has a white background and black text by default!
Minor Adjustment to getView()
For future reference, in your adapter’s getView() you call getLayoutInflater() for every new row. You only need to get the LayoutInflater once in the constructor and save it in a variable, possibly
LayoutInflater mLayoutInflater, and use this in getView() withmLayoutInflater.inflate(...).Hope that helps!