Help show data on Spinner.

Hi , i would like to show data from my database onto a spinner. how would that be possible?
As there is an null error in my logcat.

Booking.java

public class Booking extends Activity
{
    private DBAdapter db;
    private Spinner colourSpinner;
    private String txtArrival;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        db = new DBAdapter(this);
        db.open();
        setContentView(R.layout.booking);
        Cursor c = db.getSpinnerData();
        startManagingCursor(c);
        String[] from = new String[]{txtArrival};
        int[] to = new int[]{android.R.id.text1};
        SimpleCursorAdapter adapter =
        new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
        adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
        Spinner colourSpinner = (Spinner) findViewById( R.id.spinner );
        colourSpinner.setAdapter(adapter);
        }
}

DBAdapter.java

public Cursor getSpinnerData() throws SQLException
        {
            Cursor mCursor =
                    db.query(DATABASE_TABLE_2, new String[] {
                            KEY_ROWID2,
                            KEY_ARRIVAL,},
                            null,
                            null,
                            null,
                            null,
                            null);
            if (mCursor != null) {
                mCursor.moveToFirst();
            }
            return mCursor;
        }

Thank you.

This entry was posted in Codes & Scripts and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>