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:com.gsma.rcs.provisioning.local.StackProvisioning.java

@Override
public void displayRcsSettings() {
    if (sLogger.isActivated()) {
        sLogger.debug("displayRcsSettings");
    }/*w  w  w.  j  a  v  a 2  s  .co m*/
    Context ctx = getContext();
    Spinner spinner = (Spinner) mRootView.findViewById(R.id.Autoconfig);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, mConfigModes);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    ConfigurationMode mode = sRcsSettings.getConfigurationMode();
    spinner.setSelection(ConfigurationMode.AUTO.equals(mode) ? 1 : 0);

    TextView textView = (TextView) mRootView.findViewById(R.id.client_vendor);
    textView.setText(Build.MANUFACTURER);

    spinner = (Spinner) mRootView.findViewById(R.id.EnableRcsSwitch);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, mEnableRcseSwitch);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    EnableRcseSwitch rcsSwitch = sRcsSettings.getEnableRcseSwitch();
    switch (rcsSwitch) {
    case ALWAYS_SHOW:
    case ONLY_SHOW_IN_ROAMING:
        spinner.setSelection(rcsSwitch.toInt());
        break;
    default:
        spinner.setSelection(2);
    }
    mHelper.setStringEditText(R.id.SecondaryProvisioningAddress,
            RcsSettingsData.SECONDARY_PROVISIONING_ADDRESS);
    mHelper.setBoolCheckBox(R.id.SecondaryProvisioningAddressOnly,
            RcsSettingsData.SECONDARY_PROVISIONING_ADDRESS_ONLY);

    spinner = (Spinner) mRootView.findViewById(R.id.NetworkAccess);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, mNetworkAccesses);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    NetworkAccessType access = sRcsSettings.getNetworkAccess();
    switch (access) {
    case MOBILE:
        spinner.setSelection(1);
        break;
    case WIFI:
        spinner.setSelection(2);
        break;
    case ANY:
    default:
        spinner.setSelection(0);
    }
    spinner = (Spinner) mRootView.findViewById(R.id.SipDefaultProtocolForMobile);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, SIP_PROTOCOL);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    String sipMobile = sRcsSettings.getSipDefaultProtocolForMobile();
    if (SIP_PROTOCOL[0].equalsIgnoreCase(sipMobile)) {
        spinner.setSelection(0);
    } else if (SIP_PROTOCOL[1].equalsIgnoreCase(sipMobile)) {
        spinner.setSelection(1);
    } else {
        spinner.setSelection(2);
    }
    spinner = (Spinner) mRootView.findViewById(R.id.SipDefaultProtocolForWifi);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, SIP_PROTOCOL);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    String sipWifi = sRcsSettings.getSipDefaultProtocolForWifi();
    if (SIP_PROTOCOL[0].equalsIgnoreCase(sipWifi)) {
        spinner.setSelection(0);
    } else if (SIP_PROTOCOL[1].equalsIgnoreCase(sipWifi)) {
        spinner.setSelection(1);
    } else {
        spinner.setSelection(2);
    }
    String[] certificates = loadCertificatesList();
    spinner = (Spinner) mRootView.findViewById(R.id.TlsCertificateRoot);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, certificates);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    boolean found = false;
    String certRoot = sRcsSettings.getTlsCertificateRoot();
    for (int i = 0; i < certificates.length; i++) {
        if (certRoot != null && certRoot.contains(certificates[i])) {
            spinner.setSelection(i);
            found = true;
        }
    }
    if (!found) {
        spinner.setSelection(0);
        sRcsSettings.writeString(RcsSettingsData.TLS_CERTIFICATE_ROOT, "");
    }
    spinner = (Spinner) mRootView.findViewById(R.id.TlsCertificateIntermediate);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, certificates);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(0);
    found = false;
    String certInt = sRcsSettings.getTlsCertificateIntermediate();
    for (int i = 0; i < certificates.length; i++) {
        if (certInt != null && certInt.contains(certificates[i])) {
            spinner.setSelection(i);
            found = true;
        }
    }
    if (!found) {
        spinner.setSelection(0);
        sRcsSettings.writeString(RcsSettingsData.TLS_CERTIFICATE_INTERMEDIATE, "");
    }
    spinner = (Spinner) mRootView.findViewById(R.id.FtProtocol);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, FT_PROTOCOL);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    FileTransferProtocol ftProtocol = sRcsSettings.getFtProtocol();
    if (FileTransferProtocol.HTTP.equals(ftProtocol)) {
        spinner.setSelection(0);
    } else {
        spinner.setSelection(1);
    }
    mHelper.setLongEditText(R.id.ImsServicePollingPeriod, RcsSettingsData.IMS_SERVICE_POLLING_PERIOD);
    mHelper.setIntEditText(R.id.SipListeningPort, RcsSettingsData.SIP_DEFAULT_PORT);
    mHelper.setLongEditText(R.id.SipTimerT1, RcsSettingsData.SIP_TIMER_T1);
    mHelper.setLongEditText(R.id.SipTimerT2, RcsSettingsData.SIP_TIMER_T2);
    mHelper.setLongEditText(R.id.SipTimerT4, RcsSettingsData.SIP_TIMER_T4);
    mHelper.setLongEditText(R.id.SipTransactionTimeout, RcsSettingsData.SIP_TRANSACTION_TIMEOUT);
    mHelper.setLongEditText(R.id.SipKeepAlivePeriod, RcsSettingsData.SIP_KEEP_ALIVE_PERIOD);
    mHelper.setIntEditText(R.id.DefaultMsrpPort, RcsSettingsData.MSRP_DEFAULT_PORT);
    mHelper.setIntEditText(R.id.DefaultRtpPort, RcsSettingsData.RTP_DEFAULT_PORT);
    mHelper.setLongEditText(R.id.MsrpTransactionTimeout, RcsSettingsData.MSRP_TRANSACTION_TIMEOUT);
    mHelper.setLongEditText(R.id.RegisterExpirePeriod, RcsSettingsData.REGISTER_EXPIRE_PERIOD);
    mHelper.setLongEditText(R.id.RegisterRetryBaseTime, RcsSettingsData.REGISTER_RETRY_BASE_TIME);
    mHelper.setLongEditText(R.id.RegisterRetryMaxTime, RcsSettingsData.REGISTER_RETRY_MAX_TIME);
    mHelper.setLongEditText(R.id.PublishExpirePeriod, RcsSettingsData.PUBLISH_EXPIRE_PERIOD);
    mHelper.setLongEditText(R.id.RevokeTimeout, RcsSettingsData.REVOKE_TIMEOUT);
    mHelper.setLongEditText(R.id.RingingPeriod, RcsSettingsData.RINGING_SESSION_PERIOD);
    mHelper.setLongEditText(R.id.SubscribeExpirePeriod, RcsSettingsData.SUBSCRIBE_EXPIRE_PERIOD);
    mHelper.setLongEditText(R.id.IsComposingTimeout, RcsSettingsData.IS_COMPOSING_TIMEOUT);
    mHelper.setLongEditText(R.id.SessionRefreshExpirePeriod, RcsSettingsData.SESSION_REFRESH_EXPIRE_PERIOD);
    mHelper.setLongEditText(R.id.CapabilityRefreshTimeout, RcsSettingsData.CAPABILITY_REFRESH_TIMEOUT);
    mHelper.setLongEditText(R.id.CapabilityExpiryTimeout, RcsSettingsData.CAPABILITY_EXPIRY_TIMEOUT);
    mHelper.setLongEditText(R.id.CapabilityPollingPeriod, RcsSettingsData.CAPABILITY_POLLING_PERIOD);
    mHelper.setBoolCheckBox(R.id.TcpFallback, RcsSettingsData.TCP_FALLBACK);
    mHelper.setBoolCheckBox(R.id.SipKeepAlive, RcsSettingsData.SIP_KEEP_ALIVE);
    mHelper.setBoolCheckBox(R.id.PermanentState, RcsSettingsData.PERMANENT_STATE_MODE);
    mHelper.setBoolCheckBox(R.id.TelUriFormat, RcsSettingsData.TEL_URI_FORMAT);
    mHelper.setBoolCheckBox(R.id.ImAlwaysOn, RcsSettingsData.IM_CAPABILITY_ALWAYS_ON);
    mHelper.setBoolCheckBox(R.id.FtAlwaysOn, RcsSettingsData.FT_CAPABILITY_ALWAYS_ON);
    mHelper.setBoolCheckBox(R.id.FtHttpAlwaysOn, RcsSettingsData.FT_HTTP_CAP_ALWAYS_ON);
    mHelper.setBoolCheckBox(R.id.InviteOnlyGroupchatSF, RcsSettingsData.GROUP_CHAT_INVITE_ONLY_FULL_SF);
    mHelper.setBoolCheckBox(R.id.ImUseReports, RcsSettingsData.IM_USE_REPORTS);
    mHelper.setBoolCheckBox(R.id.Gruu, RcsSettingsData.GRUU);
    mHelper.setBoolCheckBox(R.id.CpuAlwaysOn, RcsSettingsData.CPU_ALWAYS_ON);
    mHelper.setBoolCheckBox(R.id.SecureMsrpOverWifi, RcsSettingsData.SECURE_MSRP_OVER_WIFI);
    mHelper.setBoolCheckBox(R.id.SecureRtpOverWifi, RcsSettingsData.SECURE_RTP_OVER_WIFI);
    mHelper.setBoolCheckBox(R.id.ImeiAsDeviceId, RcsSettingsData.USE_IMEI_AS_DEVICE_ID);
    mHelper.setBoolCheckBox(R.id.ControlExtensions, RcsSettingsData.CONTROL_EXTENSIONS);
    mHelper.setBoolCheckBox(R.id.AllowExtensions, RcsSettingsData.ALLOW_EXTENSIONS);
    mHelper.setIntEditText(R.id.MaxMsrpLengthExtensions, RcsSettingsData.MAX_MSRP_SIZE_EXTENSIONS);
    mHelper.setLongEditText(R.id.MessagingCapabilitiesValidity, RcsSettingsData.MSG_CAP_VALIDITY_PERIOD);
}

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

public void inflateOfficeSpinner() {

    safeUIBlockingUtility.safelyBlockUI();

    API.officeService.getAllOffices(new Callback<List<Office>>() {
        @Override// w  w  w  . ja  v  a2 s . com
        public void success(List<Office> offices, Response response) {

            final List<String> officeNames = new ArrayList<String>();
            officeNames.add(getString(R.string.spinner_office));
            officeNameIdHashMap.put(getString(R.string.spinner_office), -1);
            for (Office office : offices) {
                officeNames.add(office.getName());
                officeNameIdHashMap.put(office.getName(), office.getId());
            }

            ArrayAdapter<String> officeAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item, officeNames);

            officeAdapter.notifyDataSetChanged();

            officeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            sp_offices.setAdapter(officeAdapter);

            sp_offices.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                    int officeId = officeNameIdHashMap.get(officeNames.get(position));

                    if (officeId != -1) {

                        inflateStaffSpinner(officeId);
                        inflateCenterSpinner(officeId, -1);
                        inflateGroupSpinner(officeId, -1);

                    } else {

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

                    }

                }

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

                }
            });

            safeUIBlockingUtility.safelyUnBlockUI();

        }

        @Override
        public void failure(RetrofitError retrofitError) {

            System.out.println(retrofitError.getLocalizedMessage());

            safeUIBlockingUtility.safelyUnBlockUI();
        }
    });

}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditExpenseActivity.java

@Override
protected void onStart() {

    super.onStart();

    if (expense.getName() != null) {
        expenseNameInput.setText(expense.getName());
    } else {/* w w w .  ja va2  s.  c  o  m*/
        expenseNameInput.setText(expenseName);
    }

    if (expense.getDes() != null) {
        expenseDescriptionInput.setText(expense.getDes().toString());
    }

    if (expense.getCost() != null) {
        expenseCostInput.setText(expense.getCost().toString());
    }
    if (expense.getDate() != null) {
        date.setText(sdf.format(expense.getDate()));
    }

    expenseNameInput.addTextChangedListener(this);

    if (expense.getDate() != null) {
        date.setText(sdf.format(expense.getDate()));
    }

    ArrayAdapter<CharSequence> currencyAdaptor = ArrayAdapter.createFromResource(this, R.array.CurrencyArray,
            R.layout.spinner_item);
    currencyAdaptor.setDropDownViewResource(R.layout.spinner_dropdown_item);
    currencySpinner.setAdapter(currencyAdaptor);

    ArrayAdapter<CharSequence> categoryAdaptor = ArrayAdapter.createFromResource(this, R.array.CategoryArray,
            R.layout.spinner_item);
    categoryAdaptor.setDropDownViewResource(R.layout.spinner_dropdown_item);
    categorySpinner.setAdapter(categoryAdaptor);

    currencySpinner.setSelection(currencyAdaptor.getPosition(expense.getCurr()));
    categorySpinner.setSelection(categoryAdaptor.getPosition(expense.getCat()));

    setEditable();
}

From source file:com.garlicg.screenrecord4cm.SettingsActivity.java

/**
 * Create video size setting view/*from   www. ja v  a2 s .com*/
 */
private void createVideoSize(Bundle savedInstanceState) {
    int vp = mPrefs.getVideoPercentage();
    final VideoPercentage[] spinnerItems = AppPrefs.videoPercentages();
    int spinnerSelection = AppPrefs.findVideoPercentagePosition(spinnerItems, vp);

    ArrayAdapter<VideoPercentage> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            spinnerItems);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    final Spinner spinner = ViewFinder.byId(this, R.id.videoPercentageSpinner);
    spinner.setAdapter(adapter);

    spinner.setSelection(spinnerSelection);
    spinner.post(new Runnable() {
        @Override
        public void run() {
            // setSelection later
            spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    if (view == null)
                        return;

                    VideoPercentage item = (VideoPercentage) parent.getItemAtPosition(position);
                    new AppPrefs(view.getContext()).saveVideoPercentage(item);
                }

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

From source file:de.ub0r.android.otpdroid.OTPdroid.java

/**
 * {@inheritDoc}//from   w w  w .  ja v a2  s  . co  m
 */
@Override
public final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.main);

    this.passphrase = (EditText) this.findViewById(R.id.passphrase);
    this.hashMethod = (Spinner) this.findViewById(R.id.hash_method);
    this.sequence = (EditText) this.findViewById(R.id.sequence);
    this.challenge = (EditText) this.findViewById(R.id.challenge);
    this.response = (EditText) this.findViewById(R.id.response);

    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.hash_methods,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(// .
            android.R.layout.simple_spinner_dropdown_item);
    this.hashMethod.setAdapter(adapter);

    if (this.imei == null || this.simid == null) {
        this.loadKeys();
    }

    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    final String v0 = settings.getString(PREFS_LAST_RUN, "");
    final String v1 = this.getString(R.string.app_version);
    if (!v0.equals(v1)) {
        final SharedPreferences.Editor editor = settings.edit();
        editor.putString(PREFS_LAST_RUN, v1);
        editor.commit();
        this.showDialog(DIALOG_UPDATE);
    }
    this.loadPassphrase(settings);

    didCalc = false;
    this.decrementSequence();
}

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

public void inflateCenterSpinner(final int officeId, int staffId) {

    Map<String, Object> params = new HashMap<String, Object>();

    params.put(LIMIT, -1);/*from  w  w w.  j  a  v a 2  s.  com*/
    params.put(ORDER_BY, ORDER_BY_FIELD_NAME);
    params.put(SORT_ORDER, ASCENDING);
    if (staffId >= 0) {
        params.put(STAFF_ID, staffId);
    }

    API.centerService.getAllCentersInOffice(officeId, params, new Callback<List<Center>>() {
        @Override
        public void success(List<Center> centers, Response response) {

            final List<String> centerNames = new ArrayList<String>();

            centerNames.add(getString(R.string.spinner_center));
            centerNameIdHashMap.put(getString(R.string.spinner_center), -1);

            for (Center center : centers) {
                centerNames.add(center.getName());
                centerNameIdHashMap.put(center.getName(), center.getId());
            }

            ArrayAdapter<String> centerAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item, centerNames);

            centerAdapter.notifyDataSetChanged();

            centerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            sp_centers.setAdapter(centerAdapter);

            sp_centers.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                    int centerId = centerNameIdHashMap.get(centerNames.get(position));

                    if (centerId != -1) {

                        inflateGroupSpinner(centerId);

                    } else {

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

                    }

                }

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

                }
            });

        }

        @Override
        public void failure(RetrofitError retrofitError) {

            System.out.println(retrofitError.getLocalizedMessage());

        }
    });

}

From source file:com.klokisoft.mathdokuext.ui.ArchiveFragmentActivity.java

/**
 * Initializes/refreshes the sizes spinner.
 * //  ww w .ja va 2  s  . c  o m
 * Returns: True in case the sizes spinner should be shown. False otherwise.
 */
protected void setSizeSpinner() {
    Spinner spinner = (Spinner) mActionBar.getCustomView().findViewById(R.id.spinner_size);
    if (!mShowSizeFilter || mArchiveFragmentStatePagerAdapter.getCount() == 0) {
        spinner.setVisibility(View.GONE);
        return;
    }

    // Determine which sizes are actually used for the currently
    // selected status filter.
    GridDatabaseAdapter gridDatabaseAdapter = new GridDatabaseAdapter();
    final SizeFilter[] usedSizes = gridDatabaseAdapter
            .getUsedSizes(mArchiveFragmentStatePagerAdapter.getStatusFilter());

    // Load the list of descriptions for sizes actually used into the
    // array adapter.
    String[] usedSizesDescription = new String[usedSizes.length];
    for (int i = 0; i < usedSizes.length; i++) {
        usedSizesDescription[i] = getResources().getStringArray(R.array.archive_size_filter)[usedSizes[i]
                .ordinal()];
    }
    ArrayAdapter<String> adapterStatus = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            usedSizesDescription);
    adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // Build the spinner
    spinner.setAdapter(adapterStatus);

    // Restore selected size
    SizeFilter selectedSizeFilter = mArchiveFragmentStatePagerAdapter.getSizeFilter();
    for (int i = 0; i < usedSizes.length; i++) {
        if (usedSizes[i] == selectedSizeFilter) {
            spinner.setSelection(i);
            break;
        }
    }

    // Hide spinner if only two choices are available. As one of those
    // choices is always "ALL" the choices will result in an identical
    // selection.
    spinner.setVisibility((usedSizes.length <= 2 ? View.GONE : View.VISIBLE));

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Remember currently displayed grid id.
            int gridId = getCurrentSelectedGridId();

            // Get the selected status
            SizeFilter sizeFilter = usedSizes[(int) id];

            // Check if value for status spinner has changed.
            if (sizeFilter != mArchiveFragmentStatePagerAdapter.getSizeFilter()) {
                // Refresh pager adapter with new status.
                mArchiveFragmentStatePagerAdapter.setSizeFilter(sizeFilter);

                // Refresh the status spinner as the content of the spinners
                // are related.
                setStatusSpinner();

                // If possible select the grid id which was selected before
                // changing the spinner(s). Otherwise select last page.
                selectGridId(gridId);
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // Do nothing
        }
    });
}

From source file:com.klokisoft.mathdokuext.ui.ArchiveFragmentActivity.java

/**
 * Initializes/refreshes the status spinner.
 * /* w ww  .  j av a  2 s.  c om*/
 * Returns: True in case the status spinner should be shown. False
 * otherwise.
 */
protected void setStatusSpinner() {
    Spinner spinner = (Spinner) mActionBar.getCustomView().findViewById(R.id.spinner_status);
    if (!mShowStatusFilter || mArchiveFragmentStatePagerAdapter.getCount() == 0) {
        spinner.setVisibility(View.GONE);
        return;
    }

    // Determine which statuses are actually used for the currently
    // selected size filter.
    GridDatabaseAdapter gridDatabaseAdapter = new GridDatabaseAdapter();
    final StatusFilter[] usedStatuses = gridDatabaseAdapter
            .getUsedStatuses(mArchiveFragmentStatePagerAdapter.getSizeFilter());

    // Load the list of descriptions for statuses actually used into the
    // array adapter.
    String[] usedStatusesDescription = new String[usedStatuses.length];
    for (int i = 0; i < usedStatuses.length; i++) {
        usedStatusesDescription[i] = getResources()
                .getStringArray(R.array.archive_status_filter)[usedStatuses[i].ordinal()];
    }
    ArrayAdapter<String> adapterStatus = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            usedStatusesDescription);
    adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // Build the spinner
    spinner.setAdapter(adapterStatus);

    // Restore selected status
    StatusFilter selectedStatusFilter = mArchiveFragmentStatePagerAdapter.getStatusFilter();
    for (int i = 0; i < usedStatuses.length; i++) {
        if (usedStatuses[i] == selectedStatusFilter) {
            spinner.setSelection(i);
            break;
        }
    }

    // Hide spinner if only two choices are available. As one of those
    // choices is always "ALL" the choices will result in an identical
    // selection.
    spinner.setVisibility((usedStatuses.length <= 2 ? View.GONE : View.VISIBLE));

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Get the selected status
            StatusFilter statusFilter = usedStatuses[(int) id];

            // Check if value for status spinner has changed.
            if (statusFilter != mArchiveFragmentStatePagerAdapter.getStatusFilter()) {
                // Remember currently displayed grid id.
                int gridId = getCurrentSelectedGridId();

                // Refresh pager adapter with new status.
                mArchiveFragmentStatePagerAdapter.setStatusFilter(statusFilter);

                // Refresh the size spinner as the content of the spinners
                // are related.
                setSizeSpinner();

                // If possible select the grid id which was selected before
                // changing the spinner(s). Otherwise select last page.
                selectGridId(gridId);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // Do nothing
        }
    });
}

From source file:com.max2idea.android.fwknop.Fwknop.java

private void setIPs() {

    String[] arraySpinner = { "Source IP", "", "" };
    if (this.localIP != null && !this.localIP.equals("")) {
        Log.v("setter", this.localIP);
        arraySpinner[1] = this.localIP;
    } else {/*  www . j av  a 2 s  .  com*/
        sendHandlerMessage(handler, LOCALIP_NOTRESOLVED);
        return;
    }

    if (this.externalIP != null && !this.externalIP.equals("")) {
        arraySpinner[2] = this.externalIP;
        Log.v("setter", this.externalIP);
    } else {
        sendHandlerMessage(handler, EXTIP_NOTRESOLVED);
    }

    ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.simple_spinner_item, arraySpinner);
    adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    this.mAllowip.setAdapter(adapter1);
    this.mAllowip.invalidate();
}