我正在重写SpinnerAdapter并使用getView
方法。现在我的目标是设置一个默认文本,以便提示用户做什么(在这种情况下,选择一所学校)。现在我做了一个arraylist并在我的结尾处提示我。我设置了一个布尔值来检查这是否是用户第一次查看。如果是这样,我设置适当的视图并删除arraylist的最后一个元素。现在我的问题出现在我尝试选择下拉视图的第一个元素时。当我选择它时,默认文本保持不变。它只会在我选择不同视图时更改。有任何想法吗?谢谢!
boolean firstTime = true;
@Override
/**
* getView sets the spinner view when it
* isn't in drop down view.
*/
public View getView(int position, View convertView, ViewGroup parent) {
/*
* The firstTime boolean variable determines if the client
* hasn't made any previous selection. This enables a default
* text explaining to the client that they must select the
* appropriate school.
*/
if (firstTime) {
firstTime = false;
TextView firstView = new TextView(ForgotPasswordActivity.this);
firstView.setTypeface(robotoFont);
firstView.setText(spinnerSchoolList.get(spinnerSchoolList.size() - 1));
spinnerSchoolList.remove(spinnerSchoolList.size() - 1);
return firstView;
}
TextView secondView = new TextView(ForgotPasswordActivity.this);
secondView.setTypeface(robotoFont);
secondView.setText(spinnerSchoolList.get(position));
tickChange(correctEmail, selectedSchool);
return secondView;
}