Example usage for android.widget Spinner setSelection

List of usage examples for android.widget Spinner setSelection

Introduction

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

Prototype

public void setSelection(int position, boolean animate) 

Source Link

Document

Jump directly to a specific item in the adapter data.

Usage

From source file:hku.fyp14017.blencode.content.bricks.BroadcastBrick.java

protected void setSpinnerSelection(Spinner spinner) {
    int position = MessageContainer.getPositionOfMessageInAdapter(spinner.getContext(), broadcastMessage);
    spinner.setSelection(position, true);
}

From source file:hku.fyp14017.blencode.content.bricks.BroadcastReceiverBrick.java

private void setSpinnerSelection(Spinner spinner) {
    int position = MessageContainer.getPositionOfMessageInAdapter(spinner.getContext(), getBroadcastMessage());
    spinner.setSelection(position, true);
}

From source file:com.coinblesk.client.ui.dialogs.CurrencyDialogFragment.java

private void loadSettings(Context context, View... views) {
    for (View view : views) {
        view.setBackgroundResource(R.drawable.cell_shape);
    }/*from   www . jav  a 2  s . c  o m*/

    String bitcoinPrefix = SharedPrefUtils.getBitcoinScalePrefix(context);
    switch (bitcoinPrefix) {
    case "BTC":
        views[0].setBackgroundResource(R.drawable.cell_shape_currency);
        break;
    case "mBTC":
        views[1].setBackgroundResource(R.drawable.cell_shape_currency);
        break;
    case "BTC":
        views[2].setBackgroundResource(R.drawable.cell_shape_currency);
        break;
    }

    String fiat = SharedPrefUtils.getCurrency(context);
    Spinner spinner = (Spinner) views[5];
    switch (fiat) {
    case "USD":
        views[3].setBackgroundResource(R.drawable.cell_shape_currency);
        spinner.setSelection(0, false);
        break;
    case "EUR":
        views[4].setBackgroundResource(R.drawable.cell_shape_currency);
        spinner.setSelection(0, false);
        break;
    default:
        views[5].setBackgroundResource(R.drawable.cell_shape_currency);
        int pos = Arrays.asList(Constants.CURRENCIES).indexOf(fiat);
        spinner.setSelection(pos);
        break;
    }

}

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

private void setSpinnerSelection(Spinner spinner) {
    int position = MessageContainer.getPositionOfMessageInAdapter(broadcastMessage);
    if (position > 0) {
        spinner.setSelection(position, true);
    } else {//from w  w w .ja v  a 2s  .  c  om
        if (oldMessage != null && !oldMessage.equals("")) {
            spinner.setSelection(MessageContainer.getPositionOfMessageInAdapter(oldMessage), true);
        } else {
            SpinnerAdapter spinnerAdapter = spinner.getAdapter();
            if (spinnerAdapter != null && spinnerAdapter.getCount() > 1) {
                spinner.setSelection(1, true);
            } else {
                spinner.setSelection(0, true);
            }
        }
    }
}

From source file:org.jboss.aerogear.android.cookbook.aerodoc.ui.MainActivity.java

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

    application = (AeroDocApplication) getApplication();

    contentPanel = findViewById(R.id.contentPanel);

    availableLeadsFragments = new AvailableLeadsFragments();
    acceptedLeadsFragments = new AcceptedLeadsFragments();

    // -- Dropdown (Status)

    Spinner spinner = (Spinner) findViewById(R.id.status);

    ArrayAdapter<String> spinnerAdapter = (ArrayAdapter) spinner.getAdapter();
    int actualStatus = spinnerAdapter.getPosition(application.getSaleAgent().getStatus());
    spinner.setSelection(actualStatus, true);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*from  w w  w. j  a v  a2 s .  c  om*/
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
            String status = (String) adapterView.getItemAtPosition(position);
            if (!application.getSaleAgent().getStatus().equals(status)) {
                updateStatus(status);
            }
        }

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

    // -- Tabs (Leads - Available & Archived)

    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);

    pager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
    tabs.setupWithViewPager(pager);
}

From source file:com.coinblesk.client.ui.dialogs.CurrencyDialogFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.fragment_currency_dialog, null);

    final Spinner spinner = (Spinner) view.findViewById(R.id.currency_spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), R.layout.spinner_item,
            Constants.CURRENCIES);//from   ww w. ja  v  a  2s.  c  om
    spinner.setSelection(0, false);
    spinner.setAdapter(adapter);

    final TextView usd = (TextView) view.findViewById(R.id.usd);
    final TextView eur = (TextView) view.findViewById(R.id.eur);

    final TextView btc = (TextView) view.findViewById(R.id.btc);
    final TextView mbtc = (TextView) view.findViewById(R.id.mbtc);
    final TextView ubtc = (TextView) view.findViewById(R.id.ubtc);

    final View[] viewsBTC = new View[] { btc, mbtc, ubtc };
    final View[] viewsFiat = new View[] { usd, eur, spinner };

    final AlertDialog d = new AlertDialog.Builder(getActivity()).setTitle(R.string.change_currency)
            .setView(view).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    broadcastExchangeRateChanged(getActivity());
                }
            }).create();

    btc.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsBTC) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setBitcoinScalePrefix(getActivity(), "BTC");
        }
    });

    mbtc.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsBTC) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setBitcoinScalePrefix(getActivity(), "mBTC");
        }
    });

    ubtc.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsBTC) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setBitcoinScalePrefix(getActivity(), "BTC");
        }
    });

    usd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsFiat) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setCurrency(getActivity(), "USD");
        }
    });

    eur.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsFiat) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setCurrency(getActivity(), "EUR");
        }
    });

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                return;
            }
            for (View v : viewsFiat) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            spinner.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setCurrency(getActivity(), Constants.CURRENCIES[position]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            //activateSpinner(s, usd, eur);
        }
    });

    loadSettings(getActivity(), btc, mbtc, ubtc, usd, eur, spinner);

    return d;
}

From source file:de.azapps.mirakel.settings.model_settings.special_list.dialogfragments.EditDialogFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container,
        @Nullable final Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.special_lists_edit_dialog_fragment, null);
    final ArrayAdapter<CharSequence> spinnerArrayAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.special_lists_filter_type, android.R.layout.simple_spinner_dropdown_item);
    final Spinner spinner = (Spinner) rootView.findViewById(R.id.property_spinner);
    spinner.setAdapter(spinnerArrayAdapter);
    spinner.setOnItemSelectedListener(this);
    spinner.setSelection(propertyToType(property), false);
    handleNewFragment(propertyToType(property));
    final Button ok = (Button) rootView.findViewById(R.id.saveButton);
    ok.setOnClickListener(this);
    ((LinearLayout) rootView).setShowDividers(LinearLayout.SHOW_DIVIDER_END);
    return rootView;
}

From source file:com.app.blockydemo.content.bricks.ChangeVariableBrick.java

private void setSpinnerSelection(Spinner variableSpinner, UserVariable newUserVariable) {
    UserVariableAdapterWrapper userVariableAdapterWrapper = (UserVariableAdapterWrapper) variableSpinner
            .getAdapter();//from  ww w .  java  2s .  c o m

    updateUserVariableIfDeleted(userVariableAdapterWrapper);

    if (userVariable != null) {
        variableSpinner.setSelection(userVariableAdapterWrapper.getPositionOfItem(userVariable), true);
    } else if (newUserVariable != null) {
        variableSpinner.setSelection(userVariableAdapterWrapper.getPositionOfItem(newUserVariable), true);
        userVariable = newUserVariable;
    } else {
        variableSpinner.setSelection(userVariableAdapterWrapper.getCount() - 1, true);
        userVariable = userVariableAdapterWrapper.getItem(userVariableAdapterWrapper.getCount() - 1);
    }
}

From source file:li.klass.fhem.fragments.ConnectionDetailFragment.java

private void setValuesForCurrentConnection(final FHEMServerSpec connection) {
    final View view = getView();
    if (view == null)
        return;//from w  w w  . j  ava2 s  .  c om

    // We do not need to change the type selector here, as the right one is already selected.
    // We just overwrite values within the edit fields.
    if (connection.getServerType() == connectionType) {
        fillDetail(connection);
    } else {
        // We have to change the detail view to the one which is right for the current
        // connection type. However, we do not know when the selection changed listener
        // of the combo box fires. This is why we register a global listener, which is called
        // when the new view has been attached to the root view.
        // Afterwards we can continue with filling the fields with the respective values
        // of the current connection!
        detailChangedListener = new ConnectionTypeDetailChangedListener() {
            @Override
            public void onChanged() {
                detailChangedListener = null;

                fillDetail(connection);
            }
        };
        Spinner connectionTypeSpinner = (Spinner) view.findViewById(R.id.connectionType);
        connectionTypeSpinner.setSelection(selectionIndexFor(connection.getServerType()), true);
    }
}

From source file:com.ayuget.redface.ui.fragment.TopicListFragment.java

protected void initializeToolbarTitle(Toolbar toolbar) {
    View spinnerContainer = LayoutInflater.from(getActivity()).inflate(R.layout.actionbar_spinner, toolbar,
            false);//from w w w  .  j  a v  a  2 s .  c om
    ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    toolbar.addView(spinnerContainer, 0, lp);

    Spinner spinner = (Spinner) spinnerContainer.findViewById(R.id.actionbar_spinner);
    spinner.setAdapter(subcategoriesAdapter);

    // "Hack to avoid onItemSelected to be fired off on spinner instantiation
    spinner.setSelection(0, false);

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

            if (subcategoriesAdapter.getItemViewType(position) == SubcategoriesAdapter.TYPE_CATEGORY) {
                subcategory = null; // Reset subcategory filtering
            } else {
                subcategory = (Subcategory) subcategoriesAdapter.getItem(position);
            }

            loadTopics();
        }

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