【发布时间】:2015-01-07 13:49:42
【问题描述】:
我有以下代码:
public class OnboardingActivity extends BaseLoggedInActivity
implements CountryPickerDialog.ICountryPickerDialogUsers, AdapterView.OnItemSelectedListener {
private Spinner _countryCodeSpinner;
.
.
.
private void setupCountrySpinner() {
List<String> sortedCountryCodeList = CountryData.getInstance().getSortedCountryCodes();
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
R.layout.country_code_spinner_item,
sortedCountryCodeList);
_countryCodeSpinner.setOnItemSelectedListener(this);
_countryCodeSpinner.setAdapter(adapter);
_countryCodeSpinner
.setOnTouchListener(getCountryCodeSpinnerTouchListener(_countryCodeSpinner));
int position = getDefaultCountryNamePosition();
if (position >= 0) {
_countryCodeSpinner.setSelection(position);
}
}
.
.
.
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
_logger.debug("Inside onItemSelected");
view.setSelected(true);
}
我在上述函数 onItemSelected 中遇到空指针异常。它返回 NULL 视图。我从其中一位用户那里收到了这条跟踪信息,但我自己无法重现它。使用 NULL 视图调用 onItemSelected 的原因可能是什么?
谢谢
【问题讨论】:
-
这是因为
_countryCodeSpinner.setSelection(position);... listpopupwindow 不可见,所以没有视图... 您能提供此设备上的 android 版本吗? (也许在 API 11 之前微调器 listpopupwindow 更像是一个对话框) -
安卓系统版本为4.0.4
-
从后栈获取片段时遇到同样的问题。我会努力的。
-
API24 (Android7) 中的同样问题
标签: android onitemselectedlistener