Example usage for android.widget ArrayAdapter setDropDownViewResource

List of usage examples for android.widget ArrayAdapter setDropDownViewResource

Introduction

In this page you can find the example usage for android.widget ArrayAdapter setDropDownViewResource.

Prototype

public void setDropDownViewResource(@LayoutRes int resource) 

Source Link

Document

Sets the layout resource to create the drop down views.

Usage

From source file:demo.camera.library.ui.CameraCaptureActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.activity_camera_capture);

    CameraUtils.clearSessionConfig();/*w ww  . j a v a2 s .c o  m*/
    CameraUtils.clearSessionFolders(this, true, true);

    Spinner spinner = (Spinner) findViewById(R.id.filterSpinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.cameraFilterNames,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner.
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    // Define a handler that receives camera-control messages from other threads.  All calls
    // to Camera must be made on the same thread.  Note we create this before the renderer
    // thread, so we know the fully-constructed object will be visible.
    mSessionConfig = CameraUtils.getSessionConfig(this);
    CameraUtils.clearSessionConfig();

    mCameraHandler = new CameraHandler(this);
    mVideoEncoder = new TextureMovieEncoder();
    mRecordingEnabled = mVideoEncoder.isRecording();

    try {
        mMicEncoder = new MicrophoneEncoder(mSessionConfig);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Configure the GLSurfaceView.  This will start the Renderer thread, with an
    // appropriate EGL context.
    mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView);
    mGLView.setEGLContextClientVersion(2); // select GLES 2.0
    mRenderer = new CameraSurfaceRenderer(mCameraHandler, mSessionConfig, mVideoEncoder);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    mCameraManager = new AppCameraManager(this, mSessionConfig);
    setUpUi();
    Log.d(TAG, "onCreate complete: " + this);
}

From source file:com.mifos.mifosxdroid.online.GroupLoanAccountFragment.java

private void inflateLoansProductSpinner() {
    showProgress(true);/*from  ww  w . java  2 s.c  o m*/
    App.apiManager.getAllLoans(new Callback<List<ProductLoans>>() {

        @Override
        public void success(List<ProductLoans> loans, Response response) {
            /* Activity is null - Fragment has been detached; no need to do anything. */
            if (getActivity() == null)
                return;

            final List<String> loansList = new ArrayList<String>();
            for (ProductLoans loansname : loans) {
                loansList.add(loansname.getName());
                loansNameIdHashMap.put(loansname.getName(), loansname.getId());
            }
            ArrayAdapter<String> loansAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item,
                    loansList);
            loansAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
            sp_lproduct.setAdapter(loansAdapter);
            sp_lproduct.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    productId = loansNameIdHashMap.get(loansList.get(i));
                    Log.d("productId " + loansList.get(i), String.valueOf(productId));
                    if (productId != -1) {

                        inflateLoanPurposeSpinner();
                        inflateFrequencyPeriodSpinner();
                        inflateAmortizationSpinner();
                        inflateInterestCalculationPeriodSpinner();
                        //inflaterepaymentFrequencyTypeOptionsSpinner();
                        inflatetransactionProcessingStrategySpinner();
                    } else {

                        Toast.makeText(getActivity(), getString(R.string.error_select_loan), Toast.LENGTH_SHORT)
                                .show();

                    }

                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

            showProgress(false);

        }

        @Override
        public void failure(RetrofitError retrofitError) {

            Log.d(LOG_TAG, retrofitError.getLocalizedMessage());

            showProgress(false);
        }
    });

}

From source file:de.uni_koblenz_landau.apow.ObsDetailFragment.java

/**
 * Called by settings task, when loading is finished.
 *//*from w ww . ja  v  a 2  s . co m*/
@Override
public void onObsFetched(Obs obs, List<ListViewItem> testConcepts) {
    mObsDetailTask = null;

    // If result is not empty, update UI, else show error message.
    if (testConcepts != null) {
        mTestConcepts = testConcepts;
        ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(),
                android.R.layout.simple_spinner_item, mTestConcepts);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mTestConceptView.setAdapter(adapter);

        if (obs != null) {
            mObs = obs;

            // Observation is question.
            if (mObs.getConcept().getConceptId() == Constants.QUESTION_CONCEPT_ID) {
                mQuestionTextView.setText(mObs.getValueText());
                // Observation is test.
            } else if (mObs.getConcept().getConceptClass().getConceptClassId() == Constants.TEST_CLASS_ID) {
                mTestValueView.setText("" + mObs.getValueNumeric());
                mTestUnitView.setText(((ConceptNumeric) mObs.getConcept()).getUnits());

                int position = -1;
                for (int i = 0; i < adapter.getCount(); i++) {
                    if (adapter.getItem(i).getId() == mObs.getConcept().getConceptId()) {
                        position = i;
                        break;
                    }
                }
                mTestConceptView.setSelection(position);

                // Observation is finding.
            } else if (mObs.getConcept().getConceptId() == Constants.FINDING_SET_CONCEPT_ID) {
                for (Obs obs1 : mObs.getGroupMembers()) {
                    if (obs1.getConcept().getConceptId() == Constants.FINDING_CONCEPT) {
                        mFindingValueCodedView.setText(obs1.getValueCoded().getName().getName());
                        findingCode = obs1.getValueCoded().getConceptId();
                    }
                    if (obs1.getConcept().getConceptId() == Constants.FINDING_CERTAINTY
                            && obs1.getValueCoded().getConceptId() == Constants.FINDING_CERTAINTY_CONFIRMED) {
                        mFindingCertaintyView.setChecked(true);
                    }
                    if (obs1.getConcept().getConceptId() == Constants.FINDING_SEVERITY
                            && obs1.getValueCoded().getConceptId() == Constants.FINDING_SEVERITY_PRIMARY) {
                        mFindingSeverityCodedView.setChecked(true);
                    }
                }
                // Observation is symptom.
            } else if (mObs.getConcept().getConceptClass()
                    .getConceptClassId() == Constants.SYMPTOM_CONCEPT_CLASS_ID) {
                mSymptomValueView.setText(mObs.getConcept().getName().getName());
                symptomCode = mObs.getConcept().getConceptId();
            }
        } else {
            mObs = new Obs();
            mObs.setEncounter(new Encounter(mEncounterID));
        }
        restoreView();
    } else {
        Toast.makeText(getActivity(), R.string.error_database, Toast.LENGTH_SHORT).show();
    }
}

From source file:net.evecom.androidecssp.activity.event.ContinueAddActivity.java

/**
 * /*  w  w  w.  j a va  2s  .  c  o  m*/
 * 
 * 
 * @author Stark Zhou
 * @created 2015-12-30 2:45:12
 * @param view
 */

public void initDialog(View view) {
    if (monitors.size() == 0) {
        toast("", 0);
    } else {
        final View dialogView = LayoutInflater.from(ContinueAddActivity.this)
                .inflate(R.layout.monitor_add_dialog, null);
        monitorValue = (EditText) dialogView.findViewById(R.id.monitor_value);
        monitorSpin = (Spinner) dialogView.findViewById(R.id.monitor_spinner);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
                spinItems);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        monitorSpin.setAdapter(adapter);
        monitorSpin.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
                monitorType = (String) monitorSpin.getSelectedItem();
                monitorValue.setText(monitors.get(position).get("indivalue").toString());
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                monitorValue.setText(monitors.get(0).get("indivalue").toString());

            }
        });

        Dialog monitorDia = new AlertDialog.Builder(ContinueAddActivity.this)
                .setIcon(R.drawable.qq_dialog_default_icon).setTitle("").setView(dialogView)
                .setPositiveButton("", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        // map
                        if (monitorValue.getText() != null
                                && monitorValue.getText().toString().equals("") == false) {
                            monitorMap.put(monitorType.toString(), monitorValue.getText().toString());
                        } else {
                            monitorMap.put(monitorType.toString(), "--");
                        }
                        mapToStr();

                    }
                }).setNegativeButton("", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        arg0.dismiss();
                    }
                }).create();
        monitorDia.show();
    }
}

From source file:com.example.android.wearable.wear.wearnotifications.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMainRelativeLayout = (RelativeLayout) findViewById(R.id.mainRelativeLayout);
    mNotificationDetailsTextView = (TextView) findViewById(R.id.notificationDetails);
    mSpinner = (Spinner) findViewById(R.id.spinner);

    mNotificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());

    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item,
            NOTIFICATION_STYLES);/*from   w  w w . j ava 2s  .com*/
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    mSpinner.setAdapter(adapter);
    mSpinner.setOnItemSelectedListener(this);
}

From source file:com.money.manager.ex.common.CategoryListFragment.java

/**
 * Show alter binaryDialog, for create or edit new category
 *///from w ww .j av a 2s.c o  m
private void showDialogEditSubCategoryName(final SQLTypeTransaction type, final int categoryId,
        final int subCategoryId, final CharSequence subCategName) {

    // inflate view
    View viewDialog = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_new_edit_subcategory, null);

    final EditText edtSubCategName = (EditText) viewDialog.findViewById(R.id.editTextCategName);
    final Spinner spnCategory = (Spinner) viewDialog.findViewById(R.id.spinnerCategory);
    // set category description
    edtSubCategName.setText(subCategName);
    if (!TextUtils.isEmpty(subCategName)) {
        edtSubCategName.setSelection(subCategName.length());
    }

    // Fill categories list.
    CategoryService categoryService = new CategoryService(getActivity());
    final List<Category> categories = categoryService.getList();

    ArrayList<String> categoryNames = new ArrayList<>();
    ArrayList<Integer> categoryIds = new ArrayList<>();
    for (Category category : categories) {
        categoryIds.add(category.getId());
        categoryNames.add(category.getName().toString());
    }
    ArrayAdapter<String> adapterCategory = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_spinner_item, categoryNames);
    adapterCategory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spnCategory.setAdapter(adapterCategory);
    //select category if present
    if (categoryId > 0) {
        spnCategory.setSelection(categoryIds.indexOf(categoryId), true);
    }

    int titleId = type.equals(SQLTypeTransaction.INSERT) ? R.string.add_subcategory
            : R.string.edit_categoryName;

    new MaterialDialog.Builder(getContext()).customView(viewDialog, true)
            .icon(FontIconDrawable.inflate(getContext(), R.xml.ic_tag)).title(titleId)
            .positiveText(android.R.string.ok).onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    // get category description
                    String name = edtSubCategName.getText().toString();
                    // check position
                    if (spnCategory.getSelectedItemPosition() == Spinner.INVALID_POSITION)
                        return;
                    // get category id
                    int categId = categories.get(spnCategory.getSelectedItemPosition()).getId();
                    ContentValues values = new ContentValues();
                    values.put(Subcategory.CATEGID, categId);
                    values.put(Subcategory.SUBCATEGNAME, name);

                    SubcategoryRepository repo = new SubcategoryRepository(getActivity());

                    // check type transaction is request
                    switch (type) {
                    case INSERT:
                        if (getActivity().getContentResolver().insert(repo.getUri(), values) == null) {
                            Toast.makeText(getActivity(), R.string.db_insert_failed, Toast.LENGTH_SHORT).show();
                        }
                        break;
                    case UPDATE:
                        if (getActivity().getContentResolver().update(repo.getUri(), values, Subcategory.CATEGID
                                + "=" + categoryId + " AND " + Subcategory.SUBCATEGID + "=" + subCategoryId,
                                null) == 0) {
                            Toast.makeText(getActivity(), R.string.db_update_failed, Toast.LENGTH_SHORT).show();
                        }
                        break;
                    }
                    // restart loader
                    restartLoader();
                }
            }).negativeText(android.R.string.cancel).onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    dialog.cancel();
                }
            }).build().show();
}

From source file:com.zira.registration.VehicleInformationActivity.java

@Override
public void processFinish(String output, String methodName) {

    /*try {                  
       new Timer().schedule(new TimerTask() {          
     @Override/*from  w  w w. java2  s.c  o m*/
     public void run() {
         // this code will be executed after 4 seconds    
        Log.e("Inside","timer");
         value=0;
     }
       }, 10000);
               
    } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

    if (methodName.equals(fetchCountry)) {
        Log.e("fetchCountry", output);
        mainModal = parser.parseCountries(output);
        countryList = mainModal.getCountryList();

        if (SingleTon.getInstance().isEdited()) {
            value = 1;
            if (countryList.size() > 0) {
                //edit
                //gettingCountry=mProfileInfoModel.getLicenseplatecountry();//getLicenseplatecountry();
                gettingCountry = mProfileInfoModel.getLicenseplatecountryID();

                //               if(gettingCountry.equals("0"))
                //               {
                //                  gettingCountry=prefs3.getString("countryid", "");
                //                  }
                int i = 0;
                for (Country country : countryList) {
                    //edit
                    //String countryName=country.getCountryName();
                    String countryName = country.getCountryID();
                    //Log.e("", countryName);
                    if (gettingCountry.equals(countryName)) {
                        gettingCountryPosition = i;
                        System.err.println("CountryIndex=" + i);
                    }
                    i++;
                }
            }
        }

        setApapterForCountry();

    } else if (methodName.equals(fetchVehicleModals)) {
        Log.e("fetchVehicleModals", output);
        mainModal = parser.parseVehicles(output);
        vehicleArrayList = mainModal.getVehicleList();
        Log.e("fetchVehicleModals", output);
        /******************************/
        if (vehicleArrayList.size() > 0) {
            if (SingleTon.getInstance().isEdited()) {
                String gettingVehicleMake = mProfileInfoModel.getVechile_make();//"Tata";//
                //               if(gettingVehicleMake.equals(""))
                //               {
                //                  gettingVehicleMake=prefs3.getString("makename", "");
                //               }
                int i = 0;
                for (Vehicle vehicle : vehicleArrayList) {
                    String vehilmake = vehicle.getVehicleMakeName();
                    if (gettingVehicleMake.equals(vehilmake)) {
                        gettingVehicleMakePosition = i;
                    }
                    i++;
                }
            }
        }
        //*******************************Adapter to set make vehicle********************//
        ArrayAdapter<Vehicle> dataAdapter = new ArrayAdapter<Vehicle>(this, R.layout.spinner_list,
                vehicleArrayList);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //TextView tv=(TextView)findViewById(R.id.text1);
        vehicleMakeNameSpinner.setAdapter(dataAdapter);
        vehicleMakeNameSpinner.setSelection(gettingVehicleMakePosition);

        setApapterForVehicleModel(vehicleArrayList.get(gettingVehicleMakePosition).getListModalData());

        State dummyState = new State();
        stateList.clear();
        dummyState.setStateName("Licence Plate State");
        stateList.add(dummyState);
        setApapterForState();

    } else if (methodName.equals(fetchStates)) {
        Log.e("fetchStates", output);
        stateList.clear();
        mainModal = parser.parseStates(output);
        stateList = mainModal.getStateList();
        /*********************************************************/
        if (stateList.size() > 0) {
            if (value == 1) {
                //edit
                //String gettingLicenceState = mProfileInfoModel.getLicenseplatestate();
                String gettingLicenceState = mProfileInfoModel.getLicenseplatestateID();
                //               if(gettingLicenceState.equals("0"))
                //               {
                //                  gettingLicenceState=prefs3.getString("stateid","");
                //                  }
                //               
                int i = 0;
                for (State state : stateList) {
                    //edit
                    //String licenseState = state.getStateName();
                    String licenseState = state.getStateId();

                    if (gettingLicenceState.equals(licenseState)) {
                        gettingStatePosition = i;
                        System.err.println("Stateindex=" + i);
                    }
                    i++;
                }
            }
        }

        /***********************************************************/
        SingleTon.getInstance().setSelectedStates(stateList);
        setApapterForState();
    }

}

From source file:es.farfuteam.vncpp.controller.NewConnectionActivity.java

/**
 * @param savedInstanceState/*from  w w w . j a va2 s  . c  o m*/
 * @brief This is the onCreate method
 * @details The onCreate method adds buttons and edittext on the activity
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.connection_window);

    ConnectionName_field = (EditText) findViewById(R.id.ConnectionName_inserted);

    IP_field = (EditText) findViewById(R.id.IP_inserted);

    PORT_field = (EditText) findViewById(R.id.PORT_inserted);

    PSW_field = (EditText) findViewById(R.id.PSW_inserted);

    //desplegable seleccion de colores

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.color_array,
            android.R.layout.simple_spinner_item);

    Spinner_colors = (Spinner) findViewById(R.id.Spinner_colors);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    Spinner_colors.setAdapter(adapter);

    Spinner_colors.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, android.view.View v, int position, long id) {
            setColor_format(getPosEnumQuality(position));
        }

        public void onNothingSelected(AdapterView<?> parent) {
            //por defecto se selecciona la posicion 0, 24-bit color(extra-high)
            setColor_format(QualityArray.SuperHigh);
        }
    });

    Button botonConnect = (Button) findViewById(R.id.buttonConnect);
    botonConnect.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            //primero se verifica que los campos se rellenan bien,
            //y se aade a la BD antes de iniciar Canvas.

            if (verify(v)) {

                //crear usuario si todo ha ido bien
                createNewConnection();

                iniCanvasActivity();

            }

        }
    });

    Button botonCancel = (Button) findViewById(R.id.buttonCancel);
    botonCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Cancel(v);

        }
    });

    //efectos del actionBar
    final ActionBar actionBar = getActionBar();

    actionBar.setDisplayOptions(
            ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);

}

From source file:com.mifos.mifosxdroid.online.GroupLoanAccountFragment.java

private void inflateAmortizationSpinner() {
    showProgress(true);//from w  ww  .  j a  v a  2  s .c o m
    App.apiManager.getGroupLoansAccountTemplate(groupId, productId, new Callback<Response>() {
        @Override

        public void success(final Response result, Response response) {
            /* Activity is null - Fragment has been detached; no need to do anything. */
            if (getActivity() == null)
                return;

            Log.d(LOG_TAG, "Loan Account Loaded");

            final List<AmortizationType> amortizationType = new ArrayList<>();
            // you can use this array to populate your spinner
            final ArrayList<String> amortizationTypeNames = new ArrayList<String>();
            //Try to get response body
            BufferedReader reader = null;
            StringBuilder sb = new StringBuilder();
            try {
                reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
                String line;
                while ((line = reader.readLine()) != null) {
                    sb.append(line);
                }
                JSONObject obj = new JSONObject(sb.toString());
                if (obj.has("amortizationTypeOptions")) {
                    JSONArray amortizationTypes = obj.getJSONArray("amortizationTypeOptions");
                    for (int i = 0; i < amortizationTypes.length(); i++) {
                        JSONObject amortizationTypeObject = amortizationTypes.getJSONObject(i);
                        AmortizationType amortization = new AmortizationType();
                        amortization.setId(amortizationTypeObject.optInt("id"));
                        amortization.setValue(amortizationTypeObject.optString("value"));
                        amortizationType.add(amortization);
                        amortizationTypeNames.add(amortizationTypeObject.optString("value"));
                        amortizationTypeIdHashMap.put(amortization.getValue(), amortization.getId());
                    }

                }
                String stringResult = sb.toString();
            } catch (Exception e) {
                Log.e(LOG_TAG, "", e);
            }
            final ArrayAdapter<String> amortizationTypeAdapter = new ArrayAdapter<>(getActivity(),
                    layout.simple_spinner_item, amortizationTypeNames);
            amortizationTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
            sp_amortization.setAdapter(amortizationTypeAdapter);
            sp_amortization.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    amortizationTypeId = amortizationTypeIdHashMap.get(amortizationTypeNames.get(i));
                    Log.d("ammortization" + amortizationTypeNames.get(i), String.valueOf(amortizationTypeId));
                    if (amortizationTypeId != -1) {

                    } else {

                        Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT)
                                .show();

                    }

                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

            showProgress(false);

        }

        @Override
        public void failure(RetrofitError retrofitError) {

            Log.d(LOG_TAG, retrofitError.getLocalizedMessage());

            showProgress(false);
        }
    });
}

From source file:com.mifos.mifosxdroid.online.GroupLoanAccountFragment.java

private void inflateLoanPurposeSpinner() {
    showProgress(true);/*  w  ww  .  j a  v a  2  s .c om*/
    App.apiManager.getGroupLoansAccountTemplate(groupId, productId, new Callback<Response>() {
        @Override
        public void success(final Response result, Response response) {
            /* Activity is null - Fragment has been detached; no need to do anything. */
            if (getActivity() == null)
                return;

            Log.d(LOG_TAG, "");

            final List<LoanPurposeOptions> loanPurposeOptionsType = new ArrayList<>();
            // you can use this array to populate your spinner
            final ArrayList<String> loanPurposeOptionsTypeNames = new ArrayList<String>();
            //Try to get response body
            BufferedReader reader = null;
            StringBuilder sb = new StringBuilder();
            try {
                reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
                String line;
                while ((line = reader.readLine()) != null) {
                    sb.append(line);
                }
                JSONObject obj = new JSONObject(sb.toString());
                if (obj.has("loanPurposeOptions")) {
                    JSONArray loanPurposeOptionsTypes = obj.getJSONArray("loanPurposeOptions");
                    for (int i = 0; i < loanPurposeOptionsTypes.length(); i++) {
                        JSONObject loanPurposeOptionsTypesObject = loanPurposeOptionsTypes.getJSONObject(i);
                        LoanPurposeOptions loanpurpose = new LoanPurposeOptions();
                        loanpurpose.setId(loanPurposeOptionsTypesObject.optInt("id"));
                        loanpurpose.setName(loanPurposeOptionsTypesObject.optString("name"));
                        loanPurposeOptionsType.add(loanpurpose);
                        loanPurposeOptionsTypeNames.add(loanPurposeOptionsTypesObject.optString("name"));
                        loanPurposeNameIdHashMap.put(loanpurpose.getName(), loanpurpose.getId());
                    }

                }
                String stringResult = sb.toString();
            } catch (Exception e) {
                Log.e(LOG_TAG, "", e);
            }
            final ArrayAdapter<String> loanPTypeAdapter = new ArrayAdapter<>(getActivity(),
                    layout.simple_spinner_item, loanPurposeOptionsTypeNames);

            loanPTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
            sp_loan_purpose.setAdapter(loanPTypeAdapter);
            sp_loan_purpose.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    loanPurposeId = loanPurposeNameIdHashMap.get(loanPurposeOptionsTypeNames.get(i));
                    Log.d("loanpurpose" + loanPurposeOptionsTypeNames.get(i), String.valueOf(loanPurposeId));
                    if (loanPurposeId != -1) {

                    } else {

                        Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT)
                                .show();

                    }

                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

            showProgress(false);

        }

        @Override
        public void failure(RetrofitError retrofitError) {

            Log.d(LOG_TAG, retrofitError.getLocalizedMessage());

            showProgress(false);
        }
    });
}