Populate Spinner from database

by Brad Stintson » Sat, 12 Mar 2011 23:10:19 GMT


Sponsored Links
 How to populate spinner from database?

Following code is not working in my case.

This method shows database entries in spinner


private void fillData() {
     spin_pro= (Spinner)findViewById(R.id.spin_profile);
        Cursor profilesCursor = mDbHelper.retrieveAllProfiles();
        startManagingCursor(profilesCursor);


        String[] from = new String[]{DBAdapter.KEY_PRONAME};

        int[] to = new int[]{R.id.tvDBViewRow};

        SimpleCursorAdapter profile =
            new SimpleCursorAdapter(this, R.layout.profile_list,
profilesCursor, from, to);

        spin_pro.setAdapter(profile);
    }


And this is database class to retrieve data

    public Cursor retrieveAllProfiles()
    {

        return mDb.query(DATABASE_TABLE1, new String[] {KEY_PROID,
                    KEY_PRONAME, KEY_PASSWORD}, null, null, null, null,
null);
    }

-- 



Re: Populate Spinner from database

by Mark Murphy » Sat, 12 Mar 2011 23:22:55 GMT


 


Please consider defining "not working".

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!

-- 


Sponsored Links


Re: Populate Spinner from database

by davemac » Sun, 13 Mar 2011 04:46:42 GMT


 As you appear to be using a single text view in your spinner, consider
using some standard layouts and views. Instead of
R.layout.profile_list, try using android.R.layout.simple_list_item_1,
and instead of your R.id.tvDBViewRow, replace that with
android.R.id.text1. My guess is that you're getting hung up on where
these resources get specified and how. Android provides a bunch of
standard ones that you can easily use. To see the actual specification
of the layout, go to the Android SDK directory, look under the
appropriate platform directory for your target build, then under data/
res/layout. There you will find simple_list_item_1.xml which is a
layout with a single TextView in it, with an ID of text1. Anyway, try
that and see if you get better results.

- dave






-- 



Other Threads

1. Aw: how to use same activity for different listviews?

You can also put one Layout (Linear or Relative) on your main screen that 
fills the screen and use something like layout.removeLayout 
(currentlistview) && layout.addLayout ( newlistview) to change the listview. 
Or, you can use one Listview and plugin different Adapters.

I have used both for different Apps and it works.

-- 

2. SDCard installs - auto or preferExternal?

I am guessing my manifest entry is better (from the users point of
view) as:  android:installLocation="preferExternal"
Would users prefer android:installLocation="auto"?

Would app users prefer installing to their SDCard by default rather
than to internal memory?

-- 

3. jpg to bmp conversion

4. The time in status bar can't update automatically

5. [WTA] Game seru

6. Samsung Spica

7. How to implement bluetooth printer