Spinner数据绑定问题..

时间:2013-08-26 15:01:32

标签: android

您好我想将特定字段'location'从我的表绑定到android中的spinner。这是我的代码..任何人都可以帮助我吗?

Cursor cur=db.getdata();
    String[] columns=new String[]{DatabaseHandler.KEY_LOCATION};
    int[] to=new int[] {R.id.text_location};
    //ArrayAdapter<String> adapter=new ArrayAdapter<String>(Next.this,android.R.layout.simple_spinner_item);
    SimpleCursorAdapter sc=new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item,cur,columns,to,0);
    sc.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp.setAdapter(sc);

2 个答案:

答案 0 :(得分:0)

试试这个 int [] to = new int [] {android.R.id.text1};

答案 1 :(得分:0)

 Cursor cur=db.getdata();
 String[] columns=new String[]{DatabaseHandler.KEY_LOCATION};
        int[] to=new int[] {R.id.text_location};

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            android.R.layout.simple_spinner_item, 
            cur, 
            columns, 
            new int[] { android.R.id.text1 });

   adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(adapter );