我在EditText中获取默认值,即使我没有从微调器中选择。任何人都可以帮助我吗?
public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
etCountry.setText("");
switch(parent.getId()){
case R.id.spcountry:
etCountry.setText(parent.getItemAtPosition(position).toString());
break;
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
etCountry.setText("");
}
答案 0 :(得分:0)
在您的代码中,
您在此处将edittext值设置为空etCountry.setText("");
。但是你在Switch case中再次设置了值。
切换案例
case R.id.spcountry:
etCountry.setText(parent.getItemAtPosition(position).toString());//Here is where you setting the edittext value again
//Do you stuff here if you dont want default text
break;
修改强>
查找设置etCountry值的位置。转到Find-> or Press Ctl+F
。输入etCountry搜索它,您将找到设置值的位置。
希望它能解决。