Example usage for android.widget Spinner setAdapter

List of usage examples for android.widget Spinner setAdapter

Introduction

In this page you can find the example usage for android.widget Spinner setAdapter.

Prototype

@Override
public void setAdapter(SpinnerAdapter adapter) 

Source Link

Document

Sets the SpinnerAdapter used to provide the data which backs this Spinner.

Usage

From source file:me.johnmh.boogdroid.ui.BugStatusFragment.java

@NonNull
private Spinner setupStatusSpinner(View view) {
    Spinner spinnerStatus = (Spinner) view.findViewById(R.id.status);
    String statusName = bug.getStatus();
    Server server = bug.getProduct().getServer();
    StatusInfo statusInfo = server.getStatusChanges().get(statusName);
    ArrayAdapter<ChangeStatusInfo> adapter = new ArrayAdapter<>(getActivity().getBaseContext(),
            android.R.layout.simple_spinner_item, statusInfo.getChangeList());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerStatus.setAdapter(adapter);
    spinnerStatus.setSelection(adapter.getPosition(server.findChangeStatusInfo(statusName)));
    return spinnerStatus;
}

From source file:org.catrobat.catroid.content.bricks.BroadcastWaitBrick.java

@Override
public View getPrototypeView(Context context) {
    View prototypeView = View.inflate(context, R.layout.brick_broadcast_wait, null);
    Spinner broadcastWaitSpinner = (Spinner) prototypeView.findViewById(R.id.brick_broadcast_wait_spinner);
    broadcastWaitSpinner.setFocusableInTouchMode(false);
    broadcastWaitSpinner.setFocusable(false);
    SpinnerAdapter broadcastWaitSpinnerAdapter = MessageContainer.getMessageAdapter(context);
    broadcastWaitSpinner.setAdapter(broadcastWaitSpinnerAdapter);
    oldMessage = context.getString(R.string.brick_broadcast_default_value);
    setSpinnerSelection(broadcastWaitSpinner);
    return prototypeView;
}

From source file:com.dawkinstan.simplebalance.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.actionbar = getSupportActionBar();
    this.actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    this.actionbar.addTab(this.actionbar.newTab().setText("Balance").setTabListener(this));
    this.actionbar.addTab(this.actionbar.newTab().setText("Transactions").setTabListener(this));

    this.type = -1;

    // Setting display where money is shown as unclickable
    EditText cmDisplay;//from w  w  w.  j a  v a 2 s.c om
    cmDisplay = (EditText) findViewById(R.id.currentAmount);
    cmDisplay.setClickable(false);
    cmDisplay.setFocusable(false);

    Spinner spinner = (Spinner) findViewById(R.id.type_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.type_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    new Spr();

    // Getting preferences
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
    boolean firstLoad = settings.getBoolean("firstLoad", true);
    ds = new DataSource(this);

    if (firstLoad) {
        // First load intent
        Intent intent = new Intent(this, MTSettings.class);
        try {
            startActivityForResult(intent, 1);
            SharedPreferences.Editor edit = settings.edit();
            edit.putBoolean("firstLoad", false);
            edit.commit();
        } // Catches exception of the activity not existing
        catch (Exception e) {
        }
    } else {
        // Formats string to have money symbol in front.
        double currentMoney;
        try {
            currentMoney = Double.parseDouble(settings.getString("ammount", "0.00").replace("$|,", ""));
        } catch (Exception e) {
            currentMoney = 0;
        }
        this.setNewAmountInView(currentMoney);
        this.beforePurchase = currentMoney;
    }

    // Sets button as unclickable
    Button updateButton = (Button) findViewById(R.id.button_update);
    updateButton.setEnabled(false);

    // Listener to update the view of the ammount of money changed
    updateButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            onUpdate(view);
        }

    });

}

From source file:own.projects.lemiroapp.OptionsActivity.java

private void setPlayerDifficultyFor(final Player player) {

    final ArrayAdapter<String> items = new ArrayAdapter<String>(this, layout.simple_list_item_1);
    items.add("Human Player");

    for (Options.Difficulties diff : Options.Difficulties.values()) {
        items.add(diff + " Bot");
    }//from  w w  w . j  av a  2s . c o  m

    Spinner spinner = null;
    if (player.getColor().equals(Options.Color.WHITE)) {
        playerWhiteSpinner = (Spinner) findViewById(R.id.playerWhiteSpinner);
        spinner = playerWhiteSpinner;
    } else {
        playerBlackSpinner = (Spinner) findViewById(R.id.playerBlackSpinner);
        spinner = playerBlackSpinner;
    }

    spinner.setAdapter(items);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            if (pos == 0) {
                // no difficulty for human player
                return;
            } else {
                // -1 offset because first entry is the human player
                player.setDifficulty(Options.Difficulties.values()[pos - 1]);
            }
        }

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

        }

    });

    spinner.setClickable(true);
    spinner.setEnabled(true);

}

From source file:co.edu.uniajc.vtf.content.SettingsFragment.java

@Override
public void setCities(List<CityEntity> pData) {
    try {/*from w  w  w.j  a v  a  2  s  .  c  om*/
        Spinner loSpinner = (Spinner) this.getView().findViewById(R.id.spnCities);
        SpinnerCityAdapter loAdapter = new SpinnerCityAdapter(this.getActivity().getBaseContext(),
                R.layout.spinner_item, pData);
        loSpinner.setAdapter(loAdapter);
        this.coCityAdapter = loAdapter;
        this.coController.loadSettings();
        this.hideProgressDialog();
    } catch (Exception ex) {

    }
}

From source file:com.armtimes.dialogs.DialogSettings.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View settingsView = getActivity().getLayoutInflater().inflate(R.layout.dialog_settings, null);

    // Initialize and set Storage Spinner adapter.
    Spinner storageSpinner = (Spinner) settingsView.findViewById(R.id.spinnerImageStorage);
    ArrayAdapter storageAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.image_storage_array,
            android.R.layout.simple_spinner_item);
    storageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    storageSpinner.setAdapter(storageAdapter);

    storageSpinner.setSelection(getImageStorage(getActivity()));

    storageSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from  w ww. j  a v  a  2s  .c  o m
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setImageStorage(position);
        }

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

    // Initialize and set Saved news number Spinner Adapter
    Spinner savedNewsSpinner = (Spinner) settingsView.findViewById(R.id.spinnerStoredArticlesCount);
    ArrayAdapter savedNewsAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.saved_articles_number_array, android.R.layout.simple_spinner_item);
    savedNewsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    savedNewsSpinner.setAdapter(savedNewsAdapter);

    int pos = savedNewsAdapter.getPosition(Integer.toString(getAllowedNewsCount(getActivity())));
    savedNewsSpinner.setSelection(pos);

    savedNewsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final String value = (String) parent.getItemAtPosition(position);
            setSavedNewsCount(value);
        }

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

    initImageQualityControllers(settingsView);
    initFontSizeStuff(settingsView);

    // Creates About Us Alert dialog which extends from DialogFragment.
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.settings)
            .setNeutralButton(R.string.about_us_close, null).setView(settingsView).create();
}

From source file:org.alfresco.mobile.android.application.fragments.upload.UploadFormFragment.java

private void refreshImportFolder() {
    Spinner spinner = (Spinner) rootView.findViewById(R.id.import_folder_spinner);
    UploadFolderAdapter upLoadadapter = new UploadFolderAdapter(getActivity(), R.layout.sdk_list_row,
            IMPORT_FOLDER_LIST);/*  w  w w .ja va 2s  .  c o  m*/
    spinner.setAdapter(upLoadadapter);
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            folderImportId = (Integer) parent.getItemAtPosition(pos);
            importFolderIndex = pos;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // DO Nothing
        }
    });
    if (folderImportId == null) {
        importFolderIndex = 0;
    }
    spinner.setSelection(importFolderIndex);
}

From source file:co.edu.uniajc.vtf.content.SettingsFragment.java

@Override
public void setLanguages(List<LanguageEntity> pData) {
    try {/*from w  ww .java2 s  .  c  om*/
        Spinner loSpinner = (Spinner) this.getView().findViewById(R.id.spnLanguage);
        SpinnerLanguageAdapter loAdapter = new SpinnerLanguageAdapter(this.getActivity().getBaseContext(),
                R.layout.spinner_item, pData);
        loSpinner.setAdapter(loAdapter);
        this.coLanguageAdapter = loAdapter;
        this.coController.getCitiesAsync();
    } catch (Exception ex) {

    }
}

From source file:edu.teco.context.ui.Tab2Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (container == null) {
        // We have different layouts, and in one of them this
        // fragment's containing frame doesn't exist.  The fragment
        // may still be created from its saved state, but there is
        // no reason to try to create its view hierarchy because it
        // won't be displayed.  Note this is not needed -- we could
        // just run the code below, where we would create and return
        // the view hierarchy; it would just never be used.
        return null;
    }//from w  w  w.j ava 2  s  .com

    View v = inflater.inflate(R.layout.tab_frag2_layout, container, false);

    // make a copy of the context labels
    List<String> contextLabels = new ArrayList<String>(FrameworkConfiguration.getInstance().getContextLabels());

    final Spinner spinner = (Spinner) v.findViewById(R.id.spinner_activities_training);
    // Create an ArrayAdapter using the string array and a default spinner
    // layout
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(),
            android.R.layout.simple_spinner_item, contextLabels);
    // 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
    spinner.setAdapter(adapter);
    // Sets the listener for the spinner to this activity.
    spinner.setOnItemSelectedListener(this);

    return v;
}

From source file:com.armtimes.dialogs.DialogSettings.java

/**
 * This function initialize News Preview Font Size Spinner and
 * it's adapter./*from   ww w . j av  a 2  s . co  m*/
 *
 * @param settingsView Settings view with controllers.
 */
private void initFontSizeStuff(final View settingsView) {
    Spinner fontSizeSpinner = (Spinner) settingsView.findViewById(R.id.spinnerFontSize);
    // Initialize Adapter
    ArrayAdapter fontSizeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.font_size_array,
            android.R.layout.simple_spinner_item);
    fontSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    fontSizeSpinner.setAdapter(fontSizeAdapter);

    int selectedItem = 0;
    switch (getTextFontSize(getActivity())) {
    case android.R.style.TextAppearance_Medium:
        selectedItem = 1;
        break;
    case android.R.style.TextAppearance_Large:
        selectedItem = 2;
        break;
    }

    fontSizeSpinner.setSelection(selectedItem);

    fontSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setTextFontSize(position == 1 ? android.R.style.TextAppearance_Medium
                    : position == 2 ? android.R.style.TextAppearance_Large
                            : android.R.style.TextAppearance_Small);
        }

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