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

@Override
    public void setSelection(int position) 

Source Link

Usage

From source file:de.wikilab.android.friendica01.Max.java

/**
 * displays the login form (layout/loginscreen.xml) as a modal dialog and calls tryLogin
  * when user confirms the form//from   w ww .ja  va  2  s  . co m
 * @param ctx     MUST IMPLEMENT LoginListener !!!
 * @param errmes  message which is displayed above the Login form (e.g. "wrong password entered")
 */
public static void showLoginForm(final Activity ctx, String errmes) {
    Log.v(TAG, "... showLoginForm");
    View myView = ctx.getLayoutInflater().inflate(R.layout.loginscreen, null, false);
    final AlertDialog alert = new AlertDialog.Builder(ctx).setTitle("Login to Friendica").setView(myView)
            .setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    ctx.finish();
                }
            }).show();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String protocol = prefs.getString("login_protocol", "https");
    String server = prefs.getString("login_server", null);
    String userName = prefs.getString("login_user", null);

    if (errmes != null) {
        ((TextView) myView.findViewById(R.id.lblInfo)).setText(errmes);
    }

    final Spinner selProtocol = (Spinner) myView.findViewById(R.id.selProtocol);
    selProtocol.setSelection(protocol.equals("https") ? 1 : 0); //HACK !!!

    final EditText edtServer = (EditText) myView.findViewById(R.id.edtServer);
    edtServer.setText(server);

    final EditText edtUser = (EditText) myView.findViewById(R.id.edtUser);
    edtUser.setText(userName);

    final EditText edtPassword = (EditText) myView.findViewById(R.id.edtPassword);

    ((TextView) myView.findViewById(R.id.proxy_settings)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ctx.startActivity(new Intent(ctx, PreferencesActivity.class));
        }
    });

    ((Button) myView.findViewById(R.id.button1)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
            prefs.putString("login_protocol", selProtocol.getSelectedItem().toString());
            String server = edtServer.getText().toString();
            server = server.replaceAll("^https?://", "");
            prefs.putString("login_server", server);
            prefs.putString("login_user", edtUser.getText().toString());
            prefs.putString("login_password", edtPassword.getText().toString());
            prefs.commit();

            alert.dismiss();

            tryLogin(ctx);
        }
    });
}

From source file:com.hybris.mobile.app.commerce.helper.ProductHelper.java

/**
 * Fill Spinner list with arraylist of variantMatrixElement
 *
 * @param context/*from   w  ww.  j  a  va 2  s . c  om*/
 * @param spinner
 * @param variants
 * @param position
 */
public static void populateSpinner(Context context, Spinner spinner, List<VariantOption> variants,
        int position) {
    if (spinner != null && variants != null && !variants.isEmpty()) {
        VariantAdapter mVariantAdapter = new VariantAdapter(context, R.layout.item_product_variant, variants);
        spinner.setAdapter(mVariantAdapter);
        spinner.setPrompt(context.getString(R.string.choose_variant,
                ((List<VariantOptionQualifier>) variants.get(0).getVariantOptionQualifiers()).get(0)
                        .getName()));
        spinner.setVisibility(View.VISIBLE);
        spinner.setSelection(position < variants.size() ? position : 0);
    }
}

From source file:com.nextgis.mobile.map.RemoteTMSLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName,
        String layerUrl, int type, final RemoteTMSLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);/*w  w w  . j  a v a2s .  c o m*/

    final EditText url = new EditText(map.getContext());
    url.setText(layerUrl);

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    final TextView stLayerUrl = new TextView(map.getContext());
    stLayerUrl.setText(map.getContext().getString(R.string.layer_url) + ":");

    final TextView stLayerType = new TextView(map.getContext());
    stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":");

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(),
            android.R.layout.simple_spinner_item);
    final Spinner spinner = new Spinner(map.getContext());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    adapter.add(map.getContext().getString(R.string.tmstype_osm));
    adapter.add(map.getContext().getString(R.string.tmstype_normal));
    adapter.add(map.getContext().getString(R.string.tmstype_ngw));

    if (type == TMSTYPE_OSM) {
        spinner.setSelection(0);
    } else {
        spinner.setSelection(1);
    }

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);
    linearLayout.addView(stLayerUrl);
    linearLayout.addView(url);
    linearLayout.addView(stLayerType);
    linearLayout.addView(spinner);

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (spinner.getSelectedItemPosition()) {
                    case 0:
                    case 1:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 2:
                    case 3:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }

                    if (bCreate) {
                        create(map, input.getText().toString(), url.getText().toString(), tmsType);
                    } else {
                        layer.setName(input.getText().toString());
                        layer.setTMSType(tmsType);
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:com.fuzz.android.limelight.model.ChapterTransition.java

public static void getDrawerPosition() {
    LayoutInflater inflater = LimeLight.getActivity().getLayoutInflater();
    View drawerView = inflater.inflate(R.layout.choose_drawer_item, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(LimeLight.getActivity());
    builder.setTitle(R.string.choose_drawer_item);
    builder.setView(drawerView);//from   w  w w  .  ja v a 2  s.  c  o  m

    final Spinner positionSpinner = (Spinner) drawerView.findViewById(R.id.positionSpinner);

    ArrayList<String> items = new ArrayList<String>();
    for (int i = 0; i < LimeLight.getDrawerList().getAdapter().getCount(); i++) {
        items.add(i + "");
    }

    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(LimeLight.getActivity(),
            android.R.layout.simple_spinner_dropdown_item, items);

    positionSpinner.setAdapter(spinnerArrayAdapter);

    positionSpinner.setSelection(mDrawerItemPosition);

    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mDrawerItemPosition = Integer.valueOf(positionSpinner.getSelectedItem().toString());
        }
    });

    builder.setNegativeButton(R.string.cancel, null);

    builder.create();
    builder.show();
}

From source file:org.totschnig.myexpenses.dialog.DialogUtils.java

public static Spinner configureCurrencySpinner(View view, Context context,
        AdapterView.OnItemSelectedListener listener) {
    Spinner spinner = (Spinner) view.findViewById(R.id.Currency);
    ArrayAdapter<CurrencyEnum> curAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            android.R.id.text1, CurrencyEnum.sortedValues());
    curAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(curAdapter);/*from   www .j a v  a2s  .c o  m*/
    spinner.setOnItemSelectedListener(listener);
    spinner.setSelection(
            curAdapter.getPosition(CurrencyEnum.valueOf(Utils.getLocalCurrency().getCurrencyCode())));
    return spinner;
}

From source file:br.com.bioscada.apps.biotracks.util.AccountUtils.java

/**
 * Sets up account spinner.//from   w  w  w  .j  a v a2s .c  o m
 * 
 * @param fragmentActivity tyhe fragment activity
 * @param spinner the spinner
 * @param accounts the accounts
 */
public static void setupAccountSpinner(FragmentActivity fragmentActivity, Spinner spinner, Account[] accounts) {
    if (accounts.length > 1) {
        String shareTrackAccount = PreferencesUtils.getString(fragmentActivity,
                R.string.share_track_account_key, PreferencesUtils.SHARE_TRACK_ACCOUNT_DEFAULT);
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(fragmentActivity,
                R.layout.account_spinner_item);
        int selection = 0;
        for (int i = 0; i < accounts.length; i++) {
            String name = accounts[i].name;
            adapter.add(name);
            if (name.equals(shareTrackAccount)) {
                selection = i;
            }
        }
        adapter.setDropDownViewResource(R.layout.account_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setSelection(selection);
    }
}

From source file:com.nextgis.mobile.map.LocalTMSLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName, int type,
        final Uri uri, final LocalTMSLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);/*from w ww. jav a 2s. c o m*/

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(),
            android.R.layout.simple_spinner_item);
    final Spinner spinner = new Spinner(map.getContext());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    adapter.add(map.getContext().getString(R.string.tmstype_qtiles));
    adapter.add(map.getContext().getString(R.string.tmstype_osm));
    adapter.add(map.getContext().getString(R.string.tmstype_normal));
    adapter.add(map.getContext().getString(R.string.tmstype_ngw));

    if (type == TMSTYPE_OSM) {
        spinner.setSelection(1);
    } else {
        spinner.setSelection(2);
    }

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    final TextView stLayerType = new TextView(map.getContext());
    stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":");

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);
    linearLayout.addView(stLayerType);
    linearLayout.addView(spinner);

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (spinner.getSelectedItemPosition()) {
                    case 0:
                    case 1:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 2:
                    case 3:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }

                    if (bCreate) {
                        create(map, input.getText().toString(), tmsType, uri);
                    } else {
                        layer.setName(input.getText().toString());
                        layer.setTMSType(tmsType);
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:org.totschnig.myexpenses.dialog.DialogUtils.java

public static Spinner configureDateFormat(View view, Context context, String prefName) {
    Spinner spinner = (Spinner) view.findViewById(R.id.DateFormat);
    ArrayAdapter<QifDateFormat> dateFormatAdapter = new ArrayAdapter<>(context,
            android.R.layout.simple_spinner_item, QifDateFormat.values());
    dateFormatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dateFormatAdapter);
    QifDateFormat qdf;//from  w w  w . j a  va  2s. c om
    try {
        qdf = QifDateFormat.valueOf(MyApplication.getInstance().getSettings().getString(prefName, "EU"));
    } catch (IllegalArgumentException e) {
        qdf = QifDateFormat.EU;
    }
    spinner.setSelection(qdf.ordinal());
    return spinner;
}

From source file:com.skyousuke.ivtool.view.HintSpinnerAdapter.java

public void showHint(Spinner spinner) {
    spinner.setSelection(data.size() - 1);
    showHint = true;
}

From source file:com.github.kanata3249.ffxieq.android.FFXIEQBaseActivity.java

protected void updateValues() {
    for (int i = 0; i < mControlAndValues.size(); i++) {
        ControlAndValue entry = mControlAndValues.get(i);
        View control;/*from w ww  .j  a  v a2s .  com*/
        ControlBindableValue value;

        value = entry.getValue();
        control = findViewById(entry.getControlID());
        if (control != null) {
            if (control instanceof EditText) {
                EditText et = (EditText) control;
                et.setText(value.getValue());
            } else if (control instanceof Spinner) {
                Spinner spin = (Spinner) control;
                spin.setSelection(Integer.valueOf(value.getValue()));
            }
        }
    }
}