How to remove default value in spinner android?

后端 未结 1 1149
梦毁少年i
梦毁少年i 2021-02-09 04:48

I am fetching the values from Database using JSON and inserting them into spinner. This process is running successfully. But I am receiving a Spinner hint two times, when I cli

相关标签:
1条回答
  • 2021-02-09 05:00

    Use the ArrayAdapter and Override the method - getDropDownView..

    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, lables){
            @Override
            public View getDropDownView(int position, View convertView, ViewGroup parent) {             
    
                View v = null;
    
                if (position == 0) {
                    TextView tv = new TextView(getContext());
                    tv.setHeight(0);
                    tv.setVisibility(View.GONE);
                    v = tv;
                } 
                else { 
    
                    v = super.getDropDownView(position, null, parent);
                } 
    
                parent.setVerticalScrollBarEnabled(false);
                return v;
            }
        };
    

    Use the above mentioned code and remove the default value in the dropdown.

    0 讨论(0)
提交回复
热议问题