I have a Spinner
which gets populate using a SimpleCursorAdapter
. My cursor has some values, but i need the Spinner
to show an empty option by default.
I don't want to use ArrayAdapter<String>
, or CursorWrapper
in this app, for some reason.
There should be a simpler way to show an empty option in the Spinner
by default.
You can simply hide the unwanted view in the spinner adapter (getDropDownView ) :
In my sample code, defaultposition is the position to hide (like a "Select value" position)
public class SpinnerOptionAdapter extends ArrayAdapter<optionsInfos> {
...
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{ // This view starts when we click the spinner.
View row = convertView;
if(row == null)
{
LayoutInflater inflater = context.getLayoutInflater();
row = inflater.inflate(R.layout.product_tab_produit_spinner_layout, parent, false);
}
...
optionsInfos item = data.get(position);
if( (item != null) && ( position == defaultposition)) {
row.setVisibility(View.GONE);
} else {
row.setVisibility(View.VISIBLE);
}
....
return row;
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With