简体   繁体   English

单击按钮时清除微调器内容

[英]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. 这工作正常,现在我有一个按钮,点击获取值并将其他字段设置为空白,例如Edittext,如下所示。 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[]));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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