Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Populate spinner from database array

android spinner array

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 DarkHeart

DarkHeart

    CC Newcomer

  • Member
  • PipPip
  • 16 posts

Posted 06 April 2015 - 01:15 AM

I am trying to display an array of words into a spinner from the database. I tried this and it worked. But only problem is that the array of texts are all coming in one line and not each other on its own line. its showing like

wifi,ramp,lifts

Instead of each word been in its own line

Database

 

 public Cursor getAllRows() {
        String where = null;
        Cursor c = db.query(true, DATABASE_TABLE, ALL_KEYS,
                where, null, null, null, KEY_STATION_NAME, null);
        if (c != null) {
            c.moveToFirst();
        }
        return c;
    }

Java

 

public void loadtospinner() {

        Spinner spFacilityType = (Spinner) findViewById(R.id.spinnerFacilityType);

        Cursor c = dbHelper.getAllRows();
        ArrayList<String> al = new ArrayList<String>();

        c.moveToFirst();
        while (!c.isAfterLast()) {

            String name = c.getString(c.getColumnIndex(dbHelper.KEY_FACILITIES_TYPE));
            al.add(name);
            c.moveToNext();
        }

        ArrayAdapter<String> aa1 = new ArrayAdapter<String>(
                getApplicationContext(), R.layout.spinner_item, R.id.textView1,
                al);

        spFacilityType.setAdapter(aa1);

        // closing database
        dbHelper.close();

    }





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download