I have added a spinner and loaded the a list into it. Using the app
I want to select from a list. But I am unable to do it.
subDivisionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
if (isUserAction) {
if (position != selectedSubDivisionPosition) {
resetForm(false, false);
}
}
selectedSubDivision = subDivisionList.get(position);
selectedSubDivisionPosition = position;
isUserAction = true;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
When I click on spinner the list does shows but when I click on an item it goes back to the original state. i.e. the selected item is not shown after taping on it. See below image
Update 1
Below is my resetForm
method
private void resetForm(boolean all, boolean signal) {
this.refNofield1.setText("");
this.consumerNameEditText.setText("");
this.consumerAddressEditText.setText("");
this.longitudeEditText.setText("");
this.latitudeEditText.setText("");
this.placeEditText.setText("");
this.tarifEditText.setText("");
this.sLoadEditText.setText("");
this.cableLengthEditText.setText("");
this.runningLoadEntryA.setText("");
this.runningLoadEntryB.setText("");
this.runningLoadEntryC.setText("");
this.ctRatio.setText("");
this.transformerRating.setText("");
this.newSurveyImagesBitmap = new ArrayList<Bitmap>();
this.newSurveyImageSliderAdapter.setSliderImages(this.newSurveyImagesBitmap);
this.imagesNames = new ArrayList<String>();
latestSelectedImagePath = "";
refNo = "";
customerId = "";
imageCount = 0;
meterLocationRadioGroup.clearCheck();
meterTypeSpinner.setSelection(0);
meterTypeDesiredSpinner.setSelection(0);
meterTypeFieldSpinner.setSelection(0);
installTypeSpinner.setSelection(0);
meterStatusSpinner.setSelection(0);
CtRatioSpinner.setSelection(0);
TransfRateSpinner.setSelection(0);
transformerTypeSpinner.setSelection(0);
subDivisionSpinner.setSelection(0);
//meterTypeSpinner.setSelection(0);
selectedMeterType = "";
zongDataRateEdittext.setText("");
mobilinkDataRateEdittext.setText("");
telenorDataRateEdittext.setText("");
ufoneDataRateEdittext.setText("");
enableDisableDataRateEntry(false);
enableDisableOperators(false,false);
if (all) {
setSubDivs();
}
isatbSealedChecked = false;
atbSealedCheckBox.setEnabled(false);
ctQuantitySpinner.setSelection(0);
if (signal) {
zongRadioGroup.clearCheck();
waridRadioGroup.clearCheck();
mobilinkRadioGroup.clearCheck();
telenorRadioGroup.clearCheck();
if (isMobilinkChecked) {
mobilinkCheckBox.setChecked(false);
}
if (isWaridChecked) {
waridCheckBox.setChecked(false);
}
if (isTelenorChecked) {
telenorCheckBox.setChecked(false);
}
if (isZongChecked) {
zongCheckBox.setChecked(false);
}
zongType = "";
mobilinkType = "";
telenorType = "";
waridType = "";
zongDataRate = 0;
waridDataRate = 0;
telenorDataRate = 0;
mobilinkDataRate = 0;
}
}
As mentioned above, resetForm
method is resetting the value of spinner with the first item using
subDivisionSpinner.setSelection(0);
so comment this and spinner should work as expected
private void resetForm(boolean all, boolean signal) {
...
//subDivisionSpinner.setSelection(0); comment this
//meterTypeSpinner.setSelection(0);
Following @Pavneet_Sing Solution. I have done the following and it's working now
private void resetForm(boolean all, boolean signal)
{
if(all || signal)// if both true then reset form otherwise not
{
this.refNofield1.setText("");
this.consumerNameEditText.setText("");
this.consumerAddressEditText.setText("");
this.longitudeEditText.setText("");
this.latitudeEditText.setText("");
this.placeEditText.setText("");
//......
}
}
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