母语为英语的人,所以我想对你们说对不起我糟糕的英语技能。
我从 5 周前开始研究 Android。我试图实现一个微调器,我的导师问为什么需要 onNothingSelected 方法。我无话可说。
那么,为什么我需要这种方法?你能回复一下吗?
以下代码是我的微调器。它正确地完成了我的意图。
public class SpinnerViewPractice extends Activity {
private Spinner spinner;
private String spinner_value = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.spinnerviewpractice);
spinner = (Spinner)findViewById(R.id.spinner1);
String[] str = {"","good", "dislike", "like", "hate", "moderate"};
spinner.setPrompt("Set Text");
ArrayAdapter<String> list = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, str);
spinner.setAdapter(list);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
TextView tv = (TextView)arg1;
spinner_value = tv.getText().toString();
if(spinner_value.length() == 0)
{
spinner_value = "Nothing";
}
Toast.makeText(SpinnerViewPractice.this, spinner_value, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
Toast.makeText(SpinnerViewPractice.this, "NothingSelected", Toast.LENGTH_SHORT).show();
}
});
}
}