2011-09-15 22 views
0

我已经创建了一个微调器,并且微调器的项目来自数据库。然而,当我使用如何让android上的微调字符串值?

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. 
    } 
} 

当我把这个监听器,并尽量挑选微调所选择的字符串,我得到的sglite像一个参考:

[email protected] 

这是返回值typeOfBCard。

但是,在微调器上,我可以看到正常的字符串,如“工作”。

这里是我的初始化微调:

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()); 
+0

PLease添加如何初始化微调框。 – Ivan

+0

你的问题是什么?你没有得到字符串?你是否遇到异常? – AedonEtLIRA

+0

可能是[这个问题]的副本(http://stackoverflow.com/questions/5818850/android-spinner-selected-item) – theisenp

回答

0

我如何过上微调可以看到普通字符串就像那是因为你对配置的Adapter“工作”

SpinnerAdapter正在将数据拉出光标以显示。

如何让android上的微调字符串值?

没有“微调字符串值”。 Spinners没有字符串。他们有意见。这些观点可能是TextView情况下,也可能是ImageView情况下,或者如果你想要得到的数据了Cursor的,他们可能是持有到一个TextViewImageView,或...

一个的LinearLayout实例请致电拨打getString()

0

微调器中的每一行都是一个视图,但它也是来自您的源的值/对象。 尝试

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. 
} 
} 
相关问题