2

I just created an app for Android using Eclipse, and everything works, however, when I click on the Spinner, the prompt seems empty but the values are there since I can select them, what can I do to make them visible? it works in the emulator, but not on the phone, thanks!

The blank square is the prompt and the values are there! :S

    String sqlSelect = "SELECT id, name, password FROM password";
    Cursor c = db.rawQuery(sqlSelect, null);            


    Spinner sp1 = (Spinner)findViewById(R.id.spinner1);
    ArrayAdapter<String> ad = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    ad.setDropDownViewResource(android.R.layout.simple_spinner_item);
    sp1.setAdapter(ad);        

    System.out.println("Total of records is:" + c.getCount());

    if(c.moveToFirst()){
        int i = 0;

        while(c.moveToNext()){
            ad.add(c.getString(c.getColumnIndex("name")));              
            i++;
        }
    }        

Layout:

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <!-- Preview: listitem=@android:layout/simple_spinner_item -->
</Spinner>

Here's an image:

http://img163.imageshack.us/img163/659/cap201205222344.jpg

saman0suke
  • 762
  • 1
  • 8
  • 24

3 Answers3

1

In your posted image your spinner is showing some rows means its fetching values from database but you have to change spinner items background color.

Text size and background size both are white so you are unable to view text inside spinner view so try to create spinner using custom adapter or change spinner item:

ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Flexo
  • 87,323
  • 22
  • 191
  • 272
sravan
  • 5,303
  • 1
  • 31
  • 33
1

I ended up using a subclass from my ArrayAdapter, according to an example I found:

    ArrayAdapter<String> ad = new ArrayAdapter<String>(this,        android.R.layout.simple_spinner_item){
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            View view = super.getDropDownView(position, convertView, parent);

            TextView text = (TextView)view.findViewById(android.R.id.text1);
            text.setTextColor(Color.BLUE);

            return view;
        }           
    };

Now I can see the items, but I still wonder why I could see the items on the emulator but non the phone itself...thank you!!

saman0suke
  • 762
  • 1
  • 8
  • 24
0

You could use notifyDataSetChanged() which should cause a redraw of the spinner.

if(c.moveToFirst()){  
    int i = 0;  
    while(c.moveToNext()){  
        ad.add(c.getString(c.getColumnIndex("name")));                
        i++;  
}  
ad.notifyDataSetChanged();
Barak
  • 16,318
  • 9
  • 52
  • 84