Reputation: 597
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 e.g 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"
Upvotes: 0
Views: 2706
Reputation: 6715
try this
mSpner.setAdapter(new ArrayAdapter<String>(CrownTakeOrder.this, android.R.layout.simple_spinner_item, new String[]));
Upvotes: 2