1
我試圖顯示一個Spinner
列表供用戶選擇,然後選擇綁定到另一個array
。用戶選擇的值surfaceCode
已保存供以後使用。將Spinner
數組R.array.surface_option
和綁定陣列R.array.surface_code
對齊並保存在xml中。android:將微調器綁定到自定義列表
這是我的代碼...
spinnerSurface = (Spinner) findViewById(R.id.spinnerSurface);
ArrayAdapter<CharSequence> adapterSurface = ArrayAdapter.createFromResource(this, R.array.surface_option, android.R.layout.simple_spinner_item);
adapterSurface.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerSurface.setAdapter(adapterSurface);
spinnerSurface.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
TextView tx = (TextView)v;
Log.i("\n\nid",String.valueOf(tx.getText()));
String surfaceCode = getResources().getStringArray(R.array.surface_code)[spinnerSurface.getSelectedItemPosition()];
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
Log.d("code outside", surfaceCode.trim() + " is equal to SW: " + surfaceCode.trim().equals("SW"));
的surfaceCode
出來的錯誤process stopped unexpectedly
,可能是因爲它返回null
。我的代碼有什麼問題?
logcat說什麼?拋出什麼異常?請將Stacktrace添加到您的問題中。 –