最后我通过不同的教程和样本会发现这个问题的答案。对此的解决方案是:
mGender = (Spinner)findViewById(R.id.spinner1);
// Spinner method to read the on selected value
ArrayAdapter<State> spinnerArrayAdapter = new ArrayAdapter<State>(this,
android.R.layout.simple_spinner_item, new State[] {
new State("Male"),
new State("Female")});
mGender.setAdapter(spinnerArrayAdapter);
mGender.setOnItemSelectedListener(this);
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
// Get the currently selected State object from the spinner
State st = (State)mGender.getSelectedItem();
// Show it via a toast
toastState("onItemSelected", st);
}
public void toastState(String name, State st)
{
if (st != null)
{
Gen = st.name;
//Toast.makeText(getBaseContext(), Gen, Toast.LENGTH_SHORT).show();
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
您必须创建一个微调器并在onCreate方法中分配值。另外还有一个邦读取微调值。
public class State
{
public String name = "";
public State(String _name)
{
name = _name;
}
public String toString()
{
return name;
}
}
谢谢大家....
显示您logcat.Also提供你在哪里使用这些代码的细节?和你是如何管理插入,更新和删除数据库?我的意思是,你有没有创建任何类相同或不相同? – Hiral 2012-01-12 07:25:05
哪里是微调?你的代码显示textview ..所以你必须得到微调或textview的价值? – 2012-01-12 07:27:46