So I've gotten around creating dynamic spinners in Java, but I am in a bit of a pickle now. I know this is a common question, but how does one hide an item that is currently selected in the spinner? I've tried removing the items via ArrayList of strings and ArrayAdapters, but I've noticed as soon as it's removed from the list, the selection is no longer referenced to the list item either (because it does not exist anymore). I've come across an adaptation of the getDropDownView view that hides/disables the first entry from the list of items, while it is still kept in the list (link: http://pastebin.com/92BZvrkT). I would now like to use this adapter to fetch the position of the selected item and then hide it from 3 other spinners. I've got 4 spinners, they all have the same ArrayList as their resource and each one of them has its own adapter via which I used to update the array. Now, what can I do if I want to use this code given in the link (more specifically):
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;
}
};
in my onItemSelectedListener, which will look like:
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;
}