Search code examples
androidandroid-studiospinnerandroid-studio-4.0

Unable to select spinner item in android


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

enter image description here

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;
    }

}

Solution

  • 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("");
            //......
        }
    
    
    
    }