无法将微调器选中的项保存到数据库,它保存android.sqlite.cursor @而不是字符串

时间:2014-02-24 11:13:00

标签: android sqlite tostring

我的问题是sp1.getSelectedItem().toString();只将数据保存为android.database.SQLite.cursor@blablabla ...它没有得到我声明的字符串......我怎么能这样做?

这是我的游标代码[填充微调器]

 cursor = mySQLiteAdapter.queueSchoolAll();
    cursor.requery();
    String[] from1 = new String[]{Database.KSCHOOLCODE};
    int[] to1 = new int[]{R.id.rt1};       
    cursorAdapter =
        new SimpleCursorAdapter(this, R.layout.a_row_school, cursor, from1, to1);
    sp1.setAdapter(cursorAdapter);

这是保存数据的按钮代码:

 String data1 = (String)sp1.getSelectedItem().toString();
 mySQLiteAdapter.insertGrade(data1);

2 个答案:

答案 0 :(得分:1)

您需要从光标获取数据。 例如:

public xxxxxx onItemClickFunction(..., int position,....){
int pos = cursor.getPosition();//saving the position just in case

cursor.moveToPostion(position);// moving to the position where a click is fired
String val = cursor.getString(column index);

cursor.moveToPosition(pos);// moving back to original position.

}

答案 1 :(得分:1)

尝试

  String data1 = ((Cursor) sp1.getSelectedItem()).getString(0);
  mySQLiteAdapter.insertGrade(data1);