最後我通過不同的教程和樣本會發現這個問題的答案。對此的解決方案是:
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