【发布时间】:2016-10-19 13:20:11
【问题描述】:
我有一个微调器,其中有国家/地区列表,如果用户没有从列表中选择国家/地区名称,我想在微调器中显示错误,例如编辑文本。如何执行此操作?
微调器代码:
/*Country Spinner*/
m_countrySpinner = (Spinner) findViewById(R.id.country_spinner);
ArrayAdapter<CCountryStorage> adapter = new ArrayAdapter<>(getApplicationContext(), R.layout.country_spinner, CCountryListStorage.item);
m_countrySpinner.setAdapter(adapter);
m_countrySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
CCountryStorage operatorName = CCountryListStorage.item[position];
m_selectedCountryCode = operatorName.code;
Log.e(TAG, "Operator code:-" + m_selectedCountryCode);
mSpinnerItem = m_countrySpinner.getSelectedItem().toString();
if (position > 0) {
checkForEmptyField();
} else {
m_RegisterButton.setEnabled(false);
m_RegisterButton.setBackgroundColor(Color.rgb(192, 192, 192));
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
【问题讨论】:
-
错误是什么
-
你的问题解决了吗?
标签: android android-edittext spinner