我有5個紡紗廠。爲了對此做出總結。如何獲得微調器選定的項目值爲字符串?
這是微調在XML
<Spinner
android:id="@+id/text_interested"
android:layout_span="2"
android:layout_width="wrap_content"
android:layout_height="60px"
android:entries="@array/interestedarrays"
android:prompt="@string/interestedprompt" />
這是微調在Java中
submitbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
interested.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(
AdapterView<?> adapterView, View view,
int i, long l) {
interesting = interested.getItemAtPosition(i).toString();
}
public void onNothingSelected(
AdapterView<?> adapterView) {
}
});
}
});
說明這裏:
頁有一個按鈕。此按鈕將在按下時讀取微調器中的數據。我用這個檢查了輸出
System.out.println(interested.getItemAtPosition(i).toString());
它給了我什麼都不是空。
如何檢索值並將其字符串?
我肯定,你想從每當一個按鈕 – 2012-04-26 10:50:04
用戶點擊設置你的按鈕的onClick這interested.getSelectedItem()。的toString外部和內部的onclick方法使用setOnItemSelectedListener一個微調選定的項目() ; – 2012-04-26 10:58:16
謝謝,我的錯誤被放在按鈕監聽器裏面的聽衆,爲什麼沒有迴應 – 2012-04-26 11:18:48