如何在android上获取微调器字符串值?

如何在android上获取微调器字符串值?,android,sqlite,spinner,Android,Sqlite,Spinner,我已经创建了一个微调器,微调器的项目来自数据库。然而,当我使用 public class MyOnItemSelectedListener implements OnItemSelectedListener { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { typeOFBCard = contactSpinner.getSele

我已经创建了一个微调器,微调器的项目来自数据库。然而,当我使用

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) {
        typeOFBCard = contactSpinner.getSelectedItem().toString();
    }

    public void onNothingSelected(AdapterView parent) {
      // Do nothing.
    }
}
这是typeOfBCard的返回值

然而,在微调器上,我可以看到正常的字符串,如“Work”

以下是我初始化微调器的方式:

contactSpinner = (Spinner) findViewById(R.id.contactSpinner);
    mobileText =(EditText) findViewById(R.id.mobileText);
    mDbHelper = new DbAdapter(this);
    mDbHelper.open();
    cursor = mDbHelper.fetchAllBusinessCards();
    startManagingCursor(cursor);
    context =this;

    contactSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
我怎么能在旋转器上看到像“工作”这样的普通弦

这是因为您在
微调器
上配置了
适配器
,而
适配器
正在将数据从光标中拉出以显示

如何在android上获取微调器字符串值

没有“微调器字符串值”<代码>微调器没有字符串。他们有自己的观点。这些视图可能是
文本视图
的实例,或者可能是
图像视图
的实例,或者可能是按住
文本视图
图像视图
的线性布局的实例,或者


如果要从
光标
中获取数据,请在
光标
上调用
getString()
,微调器中的每一行都是视图,但它也是源中的值/对象。 试一试

公共类MyOnItemSelectedListener实现OnItemSelectedListener{
已选择公共无效项(AdapterView父项,
视图,内部位置,长id){
//父项==单击发生的位置。
typeOFBCard=parent.getSelectedItem().toString();
}
未选择公共无效(AdapterView父级){
//什么也不做。
}
}

请添加微调器的初始化方式。您有什么问题?你没拿到绳子吗?你得到一个例外吗?可能是我在上面添加了初始化部分的副本。请看一看,仍然在寻找答案。
contactSpinner = (Spinner) findViewById(R.id.contactSpinner);
    mobileText =(EditText) findViewById(R.id.mobileText);
    mDbHelper = new DbAdapter(this);
    mDbHelper.open();
    cursor = mDbHelper.fetchAllBusinessCards();
    startManagingCursor(cursor);
    context =this;

    contactSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
public class MyOnItemSelectedListener implements OnItemSelectedListener {

public void onItemSelected(AdapterView<?> parent,
    View view, int pos, long id) {
     // Parent == where the click happened. 
    typeOFBCard = parent.getSelectedItem().toString();
}

public void onNothingSelected(AdapterView parent) {
  // Do nothing.
}
}