【发布时间】:2014-05-23 08:43:58
【问题描述】:
所以我已经开始在 Java 中创建动态微调器,但我现在有点不知所措。 我知道这是一个常见问题,但是如何隐藏当前在微调器中选择的项目? 我尝试通过字符串的 ArrayList 和 ArrayAdapters 删除项目,但我注意到一旦从列表中删除,选择也不再引用到列表项(因为它不再存在)。 我遇到了对 getDropDownView 视图的改编,它隐藏/禁用了项目列表中的第一个条目,而它仍保留在列表中(链接:http://pastebin.com/92BZvrkT)。 我现在想使用这个适配器来获取所选项目的位置,然后将其隐藏在其他 3 个微调器中。 我有 4 个微调器,它们都有相同的 ArrayList 作为它们的资源,并且每个都有自己的适配器,我用来更新数组。现在,如果我想使用链接中给出的这段代码(更具体地说),我该怎么办:
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
View v = null;
// If this is the initial dummy entry, make it hidden
if (position == 0) {
TextView tv = new TextView(getContext());
tv.setHeight(0);
tv.setVisibility(View.GONE);
v = tv;
}
else {
// Pass convertView as null to prevent reuse of special case views
v = super.getDropDownView(position, null, parent);
}
// Hide scroll bar because it appears sometimes unnecessarily, this does not prevent scrolling
parent.setVerticalScrollBarEnabled(false);
return v;
}
};
在我的 onItemSelectedListener 中,它看起来像:
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
boolean countertest = false;
switch(parent.getId())
{
case R.id.spinner_1:
//there used to be the removal from the list and adding to it, until I've noticed my fatal mistake (removal of selected item)
//I want to add the upper method, getDropDownView here somewhere, so I can control which item gets hidden
break;
case R.id.spinner_2:
//... same here
break;
}
【问题讨论】: