简体   繁体   中英

Clear spinner contents on button click

I have a spinner that is dynamically loaded with data as following

final  String[] sku = CrownApplication.mDb.getAllSKUs(Qsearch);
                if((sku.length>=1)){ 
                ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(CrownTakeOrder.this,android.R.layout.simple_spinner_item, sku);
                dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                mSpner.setAdapter(dataAdapter);

                }

This works fine,now I have a button that on clicking gets the value and sets other fields blank eg Edittext as below. The only problen is I am not able to clear the spinner so once everything else is cleared the spinner still remains with the old Values

if (!mError) {
                mSKU = mSpner.getSelectedItem().toString();
                Qsearch =mQuery.getText().toString();
                quantity =mQuantity.getText().toString();
                String[] parts = mSKU.split(" - ");
                str1 = parts[0];  
                str2 = parts[1];   

                addBody(Qsearch,mSKU,quantity);

                mQuery.setText("");
                mTxtview.setText("");
                mQuantity.setText("");
                mSKU = "empty";

               //mSpner.setAdapter(null);

            } 

I have tried to use

 mSpner.setAdapter(null);

But my app crashes....How to empty spinner? I am coding on

android:minSdkVersion="11"
    android:targetSdkVersion="15"

尝试这个

mSpner.setAdapter(new ArrayAdapter<String>(CrownTakeOrder.this, android.R.layout.simple_spinner_item, new String[]));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM