0
我試着用調用微調器來編輯edittext。所有的作品,但onItemSelected不在調入者調用帶微調控制器的EditText
final String[] items = new String[] {"Item1", "Item2", "Item3"};
final Spinner spinner = new Spinner(this);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
city.setOnFocusChangeListener(new OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus)
{
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(city.getWindowToken(), 0);
spinner.performClick();
}
}
});
調用微調器並選擇項目後沒有任何事情發生。沒有呼叫Spinner聽衆。有任何想法嗎?
04-24 15:19:32.897:E/AndroidRuntime(7769):引起:java.lang.RuntimeException:setOnItemClickListener不能與微調器一起使用。 – user1021984 2012-04-24 11:21:16
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);刪除此行並嘗試使用setOnItemClickListener – 2012-04-24 11:25:18
再次出現此錯誤 – user1021984 2012-04-24 11:32:53