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:edu.teco.context.ui.Tab4Fragment.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;
    }//www . j  av a 2  s.co  m

    View v = inflater.inflate(R.layout.tab_frag4_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_evaluation);
    // 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.example.android.fragments._3_IncidentDescription.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ll = (RelativeLayout) inflater.inflate(R.layout.incidentdescription, container, false);
    sendbutton = ((Button) ll.findViewById(R.id.descr_finished_button));
    sendbutton.setOnClickListener(this);
    locdescrp = ((TextView) ll.findViewById(R.id.detailed_location_description));
    locdescrp.setOnClickListener(this);
    damagdescrinfo = ((TextView) ll.findViewById(R.id.damage_description_information));
    damagdescrinfo.setOnClickListener(this);
    Spinner spinner = ((Spinner) ll.findViewById(R.id.facilities_spinner));
    //spinner.setOnClickListener(this);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(ll.getContext(), R.array.facilities,
            android.R.layout.simple_spinner_item);
    // 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);

    // Inflate the layout for this fragment
    return ll;/* ww  w. j  a v  a  2 s  .  c om*/
}

From source file:com.cachirulop.moneybox.activity.MovementDetailActivity.java

/**
 * Load the spinner with the available money coins and bills.
 *///w  ww  . j a v a2 s . c o m
private void loadSpinner() {
    Spinner spn;

    spn = (Spinner) findViewById(R.id.sAmount);
    spn.setAdapter(new CurrencySpinnerAdapter(this));
}

From source file:com.friedran.appengine.dashboard.gui.DashboardLoadFragment.java

private Spinner setSpinnerWithItems(LinearLayout layout, int optionsListResourceID, int spinnerResourceID) {
    Spinner spinner = (Spinner) layout.findViewById(spinnerResourceID);

    // Set options list
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mActivity, optionsListResourceID,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    // Set listener
    spinner.setOnItemSelectedListener(this);

    return spinner;
}

From source file:fr.cph.stock.android.activity.OverallActivity.java

private void showPanelUpdateHistory() {
    final Dialog alert = new Dialog(this);
    alert.setTitle("Update history");
    alert.setContentView(R.layout.history_dialog);

    final Spinner checked = (Spinner) alert.findViewById(R.id.accountList);
    List<String> list = new ArrayList<String>();
    for (Account acc : portfolio.getAccounts()) {
        list.add(acc.getName());//from   w w  w .ja  va  2s . com
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    checked.setAdapter(dataAdapter);

    Button dialogButton = (Button) alert.findViewById(R.id.dialogButtonOK);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            refreshItem.setActionView(R.layout.progressbar);
            refreshItem.expandActionView();
            Account account = portfolio.getAccounts().get(checked.getSelectedItemPosition());
            EditText liquidityView = (EditText) alert.findViewById(R.id.liquidityMov);
            EditText yieldView = (EditText) alert.findViewById(R.id.yield);
            EditText buyView = (EditText) alert.findViewById(R.id.buy);
            EditText sellView = (EditText) alert.findViewById(R.id.sell);
            EditText taxeView = (EditText) alert.findViewById(R.id.taxe);
            EditText commentaryView = (EditText) alert.findViewById(R.id.commentaryEditText);

            String params = null;
            params = "?accountId=" + account.getId() + "&liquidity=" + liquidityView.getText() + "&yield="
                    + yieldView.getText() + "&buy=" + buyView.getText() + "&sell=" + sellView.getText()
                    + "&taxe=" + taxeView.getText() + "&commentary="
                    + commentaryView.getText().toString().replaceAll(" ", "%20");
            MainTask mainTask = new MainTask(OverallActivity.this, UrlType.UPDATEHISTORY, params);
            mainTask.execute((Void) null);
            alert.dismiss();
        }
    });
    dialogButton = (Button) alert.findViewById(R.id.dialogButtonCancel);
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            alert.dismiss();
        }
    });
    alert.show();
}

From source file:com.xyproto.archfriend.ArchFriendActivity.java

private void populateSpinner() throws InterruptedException, ExecutionException {
    Spinner spinner = (Spinner) findViewById(R.id.lstMaintainers);

    List<Maintainer> maintainers = ArchWeb.getMaintainers();

    if (!maintainers.isEmpty()) {
        ArrayAdapter<Maintainer> adapter = new ArrayAdapter<Maintainer>(this,
                android.R.layout.simple_spinner_item, maintainers);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override// www  .j a v a2s  . co  m
            public void onItemSelected(AdapterView<?> adapter, View v, int i, long lng) {
                TextView tvNews = (TextView) findViewById(R.id.txtArchNews);
                Maintainer maintainer = (Maintainer) adapter.getAdapter().getItem(i);

                String outputText = null;
                try {
                    List<Package> packages = ArchWeb.getFlaggedPackages(maintainer);

                    outputText = maintainer.getFullName();
                    if (packages.isEmpty()) {
                        outputText += " "
                                + String.format(getString(R.string.flagged_ood), getString(R.string.zero));
                    } else if (packages.size() == 1) {
                        outputText += " " + getString(R.string.only_one);
                        outputText += "\n\n" + packages.get(0);
                    } else {
                        outputText += " " + String.format(getString(R.string.flagged_ood), packages.size());
                        outputText += "\n\n";
                        for (Package pkg : packages) {
                            outputText += pkg + "\n";
                        }
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }

                if (spinnerCanChangeStuffYet) {
                    if (outputText != null)
                        tvNews.setText(outputText);
                    else
                        tvNews.setText(R.string.no_maintainers);

                    scrollHome();
                } else {
                    // This is to avoid the spinner from overwriting the
                    // news with the initial default selection
                    spinnerCanChangeStuffYet = true;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                TextView tv = (TextView) findViewById(R.id.txtArchNews);
                if (spinnerCanChangeStuffYet) {
                    tv.setText("");
                    scrollHome();
                }
            }

        });
    } else {
        spinner.setVisibility(View.INVISIBLE);
        TextView tvNoData = (TextView) findViewById(R.id.tvNoData);
        tvNoData.setVisibility(View.VISIBLE);
    }
}

From source file:edu.teco.context.ui.Tab1Fragment.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;
    }/* w  w w  .j  a  v  a  2 s.  c om*/

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

    List<String> probeNames = FrameworkConfiguration.getInstance().getSupportedProbeNames();

    final Spinner spinner = (Spinner) v.findViewById(R.id.spinner_sensors);
    // 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, probeNames);
    // 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);
    if (probeNames.size() > 0) {
        mProbeKey = probeNames.get(0);
    }

    final Button addButton = (Button) v.findViewById(R.id.buttonAddProbe);
    addButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            addSensorFeatureCombination(v);
        }
    });

    return v;
}

From source file:com.creationgroundmedia.popularmovies.MovieListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);
    inflater.inflate(R.menu.menu_fragment, menu);
    /**//from   w ww . j  a va 2s  .  co  m
     * use a spinner to select sort order, that way the user can always see what the order is
     */
    MenuItem item = menu.findItem(R.id.action_sorting_spinner);
    Spinner sortingSpinner = (Spinner) MenuItemCompat.getActionView(item);
    ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.sorting_modes,
            R.layout.spinner_item);
    spinnerAdapter.setDropDownViewResource(R.layout.spinner_item);
    sortingSpinner.setAdapter(spinnerAdapter);
    sortingSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            sortOrder = sortOrders[position];
            movieCursorLoader = getSupportLoaderManager().restartLoader(URL_LOADER, null,
                    MovieListActivity.this);
            recyclerView.getAdapter().notifyDataSetChanged();
        }

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

    item = menu.findItem(R.id.action_faves_only);
    Button faveButton = (Button) MenuItemCompat.getActionView(item);
    faveButton.setSelected(mFavoritesOnly);
    faveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFavoritesOnly = !v.isSelected();
            v.setSelected(mFavoritesOnly);
            mSelectFavorites = mFavoritesOnly ? MoviesContract.MovieEntry.COLUMN_FAVORITE + " = 1" : null;
            movieCursorLoader = getSupportLoaderManager().restartLoader(URL_LOADER, null,
                    MovieListActivity.this);
        }
    });

    return super.onCreateOptionsMenu(menu);
}

From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.socialmedia.twitter.TwitterFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_recycler_with_spinner_swipe_refresh, null);

    mRecyclerView = root.findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new TwitterItemAdapter(null);

    mRecyclerView.setAdapter(mAdapter);/*from   w  w  w.  j a v  a 2  s  .  c  o  m*/

    // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are
    // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity.
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    swipeRefreshLayout = root.findViewById(R.id.swipe_container);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light,
            R.color.holo_orange_light, R.color.holo_red_light);

    mEmptyView = root.findViewById(R.id.empty_list_view);

    Spinner spinner = root.findViewById(R.id.fragment_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.twitter_accounts,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    viewModel = ViewModelProviders.of(this, viewModelFactory).get(TwitterViewModel.class);

    viewModel.getResourceStatus().observe(this, resourceStatus -> {
        if (resourceStatus != null) {
            switch (resourceStatus.status) {
            case LOADING:
                swipeRefreshLayout.setRefreshing(true);
                break;
            case SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                break;
            case ERROR:
                swipeRefreshLayout.setRefreshing(false);
                TextView t = (TextView) mEmptyView;
                t.setText(R.string.no_connection);
                mEmptyView.setVisibility(View.VISIBLE);
                Toast.makeText(getContext(), "connection error", Toast.LENGTH_SHORT).show();
            }
        }
    });

    viewModel.getTwitterPosts().observe(this, twitterItems -> {
        if (twitterItems != null) {
            mEmptyView.setVisibility(View.GONE);
            if (!twitterItems.isEmpty()) {
                mAdapter.setData(twitterItems);
            } else {
                TextView t = (TextView) mEmptyView;
                t.setText("tweets unavailable.");
                mEmptyView.setVisibility(View.VISIBLE);
            }
        }
    });

    viewModel.refresh();

    return root;
}

From source file:org.alfresco.mobile.android.application.fragments.node.create.CreateDocumentDialogFragment.java

private View createView(LayoutInflater inflater, ViewGroup container) {
    // Configuration available ?
    ConfigService configService = ConfigManager.getInstance(getActivity()).getConfig(getAccount().getId(),
            ConfigTypeIds.CREATION);/*from w ww. j av a2 s  .  c o  m*/
    if (configService != null) {
        createConfigManager = new CreateConfigManager(getActivity(), configService, (ViewGroup) getRootView());
    }

    View rootView = inflater.inflate(R.layout.sdk_create_content_props, container, false);
    tv = (MaterialEditText) rootView.findViewById(R.id.content_name);
    desc = (MaterialEditText) rootView.findViewById(R.id.content_description);
    tags = (MaterialEditText) rootView.findViewById(R.id.content_tags);
    TextView tsize = (TextView) rootView.findViewById(R.id.content_size);

    if (getArguments().getSerializable(ARGUMENT_CONTENT_FILE) != null) {
        contentFile = (ContentFile) getArguments().getSerializable(ARGUMENT_CONTENT_FILE);
        tempName = contentFile.getFileName();
        tv.setText(tempName);
        tsize.setText(Formatter.formatFileSize(getActivity(), contentFile.getLength()));
        tsize.setVisibility(View.VISIBLE);
    } else {
        tsize.setVisibility(View.GONE);
    }

    tv.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            tempName = tv.getText().toString();
            if (tv.getText().length() == 0) {
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                tv.setError(null);
            } else {
                if (UIUtils.hasInvalidName(tv.getText().toString().trim())) {
                    tv.setError(getString(R.string.filename_error_character));
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                } else {
                    tv.setError(null);
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                    if (!requestInProgress) {
                        Operator.with(getActivity(), getAccount()).load(
                                new RetrieveDocumentNameRequest.Builder(getParent(), tv.getText().toString()));
                        requestCheck = false;
                        requestInProgress = true;
                    } else {
                        requestCheck = true;
                    }
                }
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
    });

    tags.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (!((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).isEnabled()) {
                return false;
            }
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                createDocument(tv, desc);
                handled = true;
            }
            return handled;
        }
    });

    Folder parentFolder = getParent();

    Operator.with(getActivity(), getAccount())
            .load(new RetrieveDocumentNameRequest.Builder(parentFolder, contentFile.getFileName()));

    // Custom type
    if (createConfigManager != null) {
        DisplayUtils.show(rootView, R.id.types_group);
        Spinner spinner = (Spinner) rootView.findViewById(R.id.types_spinner);
        TypeAdapter adapter = new TypeAdapter(getActivity(), R.layout.row_single_line,
                createConfigManager.retrieveCreationDocumentTypeList());
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                type = (ItemConfig) parent.getItemAtPosition(pos);
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // DO Nothing
            }
        });
        if (adapter.isEmpty()) {
            DisplayUtils.hide(rootView, R.id.types_group);
        }
    } else {
        DisplayUtils.hide(rootView, R.id.types_group);
    }

    return rootView;
}