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:com.xilconic.dominiontoolkit.Activities.GameSetup.GameSetupFragment.java

private void setViews(View fragmentView) {
    // Setup player count selection Spinner:
    Spinner playerSpinner = (Spinner) fragmentView.findViewById(R.id.dominoinGameSetupPlayerSpinner);
    playerSpinner.setSelection(gameSetup.getPlayerCount() - 2);

    // Setup ExpandableList:
    expandableList = (ExpandableListView) fragmentView.findViewById(R.id.dominionGameSetupExpandableListView);
    adapter = new GameSetupExpandableListAdapter(getActivity(), gameSetup);
    expandableList.setAdapter(adapter);/* w  w  w.j a v a 2s.  c om*/

    // Expand the Kingdom Cards group:
    int kingdomCardsGroupId = adapter.getKingdomCardsGroupId();
    expandableList.expandGroup(kingdomCardsGroupId);
}

From source file:io.oceanos.shaderbox.dialog.PropertiesDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final Shader shader = (Shader) getArguments().getSerializable("shader");

    View view = inflater.inflate(R.layout.dialog_properties, null);
    final EditText nameView = (EditText) view.findViewById(R.id.name);
    Switch vrMode = (Switch) view.findViewById(R.id.vr_mode);
    Switch preview = (Switch) view.findViewById(R.id.preview);
    Spinner resolutionFactor = (Spinner) view.findViewById(R.id.resolution_factor);
    resolutionFactor.setSelection(Integer.numberOfTrailingZeros(shader.getResolution()));
    resolutionFactor.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*from   w  w  w.java 2s .c om*/
        public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) {
            shader.setResolution(1 << pos);
        }

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

    nameView.setText(shader.getName());

    vrMode.setChecked(shader.getVrMode() == 1);
    vrMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            shader.setVrMode(isChecked ? 1 : 0);
        }
    });

    preview.setChecked(shader.getPreviewMode() == 1);
    preview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            shader.setPreviewMode(isChecked ? 1 : 0);
        }
    });

    builder.setTitle(R.string.properties).setView(view)
            .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    shader.setName(nameView.getText().toString());
                    mListener.onSave(shader);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    mListener.onCancel(shader);
                }
            });

    return builder.create();
}

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

@Override
public void onResume() {
    super.onResume();
    if (FrameworkContext.INFO)
        Log.i(TAG, "Fragment returned and context label is: " + TabsFragmentActivity.getCurrentContextLabel());
    int contextLabelIndex = FrameworkConfiguration.getInstance().getContextLabels()
            .indexOf(TabsFragmentActivity.getCurrentContextLabel());
    Spinner spinner = (Spinner) getActivity().findViewById(R.id.spinner_activities_training);
    spinner.setSelection(contextLabelIndex);

    Button trainingButton = (Button) getActivity().findViewById(R.id.buttonTrain);
    if (trainingButton != null) {
        FrameworkState state = ((TabsFragmentActivity) getActivity()).framework.getCurrentState();
        if (state == FrameworkState.TRAINING) {
            trainingButton.setText(R.string.button_stop_recording);
        } else {/*from w w w.j  av a  2s  .  c o m*/
            trainingButton.setText(R.string.button_start_recording);
        }
    }
}

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

@Override
public void onResume() {
    super.onResume();
    if (FrameworkContext.INFO)
        Log.i(TAG, "Fragment returned and context label is: " + TabsFragmentActivity.getCurrentContextLabel());
    int contextLabelIndex = FrameworkConfiguration.getInstance().getContextLabels()
            .indexOf(TabsFragmentActivity.getCurrentContextLabel());
    Spinner spinner = (Spinner) getActivity().findViewById(R.id.spinner_activities_evaluation);
    spinner.setSelection(contextLabelIndex);

    Button trainingButton = (Button) getActivity().findViewById(R.id.buttonEvaluating);
    if (trainingButton != null) {
        FrameworkState state = ((TabsFragmentActivity) getActivity()).framework.getCurrentState();
        if (state == FrameworkState.EVALUATING) {
            trainingButton.setText(R.string.button_stop_recording);
        } else {//from   w  w w.j  av a  2 s  .  c o  m
            trainingButton.setText(R.string.button_start_recording);
        }
    }
}

From source file:fr.julienvermet.bugdroid.ui.phone.BugActivity.java

/**
 * Searches the view hierarchy excluding the content view for a possible
 * Spinner in the ActionBar.//from ww w.  j  a v a  2 s. co  m
 * 
 * @param root
 *            The parent of the content view
 * @param position
 *            The position that should be selected
 * @return if the spinner was found and adjusted
 */
private boolean findAndUpdateSpinner(Object root, int position) {
    if (root instanceof android.widget.Spinner) {
        // Found the Spinner
        Spinner spinner = (Spinner) root;
        spinner.setSelection(position);
        return true;
    } else if (root instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) root;
        if (group.getId() != android.R.id.content) {
            // Found a container that isn't the container holding our screen
            // layout
            for (int i = 0; i < group.getChildCount(); i++) {
                if (findAndUpdateSpinner(group.getChildAt(i), position)) {
                    // Found and done searching the View tree
                    return true;
                }
            }
        }
    }
    // Nothing found
    return false;
}

From source file:se.hockersten.timed.vibration.main.PracticeTab.java

@Override
public void onResume() {
    Button startBtn = (Button) getActivity().findViewById(R.id.mainPractice_btnStart);
    startBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            flipCounting();/*from ww w  . j  a v  a2s  .  co  m*/
            updateUI();
        }
    });
    SharedPreferences sharedPrefs = getActivity().getPreferences(Context.MODE_PRIVATE);
    Spinner spinFirst = (Spinner) root.findViewById(R.id.mainPractice_spinIntervalFirst);
    spinFirst.setSelection(sharedPrefs.getInt(SPIN_FIRST_POS, 1)); // 1 minute by default
    Spinner spinSecond = (Spinner) root.findViewById(R.id.mainPractice_spinIntervalSecond);
    spinSecond.setSelection(sharedPrefs.getInt(SPIN_SECOND_POS, 3)); // 5 minutes by default
    updateUI();
    super.onResume();
}

From source file:com.akop.bach.fragment.playstation.GameCatalogFilterFragment.java

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

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setView(layout)
            .setTitle(R.string.catalog_filter_u)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    mAccount.setCatalogConsole(mConsole);
                    mAccount.setCatalogReleaseStatus(mReleaseStatus);
                    mAccount.setCatalogSortOrder(mSortOrder);
                    mAccount.save(Preferences.get(getActivity()));

                    if (mOkListener != null)
                        mOkListener.okClicked(mConsole, mReleaseStatus, mSortOrder);

                    dismiss();//w w  w .  j  av a  2 s  . com
                }
            }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismiss();
                }
            });

    RadioButton btn;

    btn = (RadioButton) layout.findViewById(R.id.filter_order_alpha);
    btn.setChecked(mSortOrder == PSN.CATALOG_SORT_BY_ALPHA);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mSortOrder = PSN.CATALOG_SORT_BY_ALPHA;
        }
    });

    btn = (RadioButton) layout.findViewById(R.id.filter_order_reldate);
    btn.setChecked(mSortOrder == PSN.CATALOG_SORT_BY_RELEASE);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mSortOrder = PSN.CATALOG_SORT_BY_RELEASE;
        }
    });

    btn = (RadioButton) layout.findViewById(R.id.filter_rs_coming_soon);
    btn.setChecked(mReleaseStatus == PSN.CATALOG_RELEASE_COMING_SOON);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mReleaseStatus = PSN.CATALOG_RELEASE_COMING_SOON;
        }
    });

    btn = (RadioButton) layout.findViewById(R.id.filter_rs_out_now);
    btn.setChecked(mReleaseStatus == PSN.CATALOG_RELEASE_OUT_NOW);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mReleaseStatus = PSN.CATALOG_RELEASE_OUT_NOW;
        }
    });

    Spinner spin = (Spinner) layout.findViewById(R.id.filter_console);
    spin.setSelection(mConsole);
    spin.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            mConsole = arg2;
        }

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

    View view = layout.findViewById(R.id.filter_rs);
    view.setVisibility(mAccount.supportsFilteringByReleaseDate() ? View.VISIBLE : View.GONE);

    return builder.create();
}

From source file:com.github.johnpersano.supertoasts.demo.fragments.AttributeSpinnerFragment.java

@Nullable
@Override//  www  .  j  a va  2  s  .co m
@SuppressWarnings("ConstantConditions")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_attribute_spinner, container, false);

    if (this.getArguments() == null) {
        throw new IllegalArgumentException(
                getClass().getName().concat(" cannot be " + "instantiated without arguments."));
    }

    final TextView titleTextView = (TextView) view.findViewById(R.id.title);
    titleTextView.setText(getArguments().getString(ARG_SUBTITLE));

    final TextView summaryTextView = (TextView) view.findViewById(R.id.summary);
    summaryTextView.setText(getArguments().getString(ARG_SUMMARY));

    final Spinner spinner = (Spinner) view.findViewById(R.id.spinner);
    spinner.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item,
            getArguments().getStringArray(ARG_ARRAY_ID)));
    spinner.setSelection(PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getInt(getArguments().getString(ARG_TITLE), 0));
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
                    .putInt(getArguments().getString(ARG_TITLE), position).commit();
        }

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

    return view;
}

From source file:org.botlibre.sdk.activity.issuetracker.EditIssueActivity.java

public void resetView() {
    HttpGetImageAction.fetchImage(this, MainActivity.issue.avatar, findViewById(R.id.icon));

    HttpAction action = new HttpGetTagsAction(this, "Issue");
    action.execute();/*from   w ww .  java  2 s  .com*/

    IssueConfig instance = MainActivity.issue;

    AutoCompleteTextView tagsText = (AutoCompleteTextView) findViewById(R.id.tagsText);
    tagsText.setText(instance.tags);

    EditText text = (EditText) findViewById(R.id.titleText);
    text.setText(instance.title);
    text = (EditText) findViewById(R.id.detailsText);
    text.setText(instance.details);

    Spinner spin = (Spinner) findViewById(R.id.prioritySpin);
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,
            MainActivity.priorities);
    spin.setAdapter(adapter);
    spin.setSelection(Arrays.asList(MainActivity.priorities).indexOf(instance.priority));

    //CheckBox checkbox = (CheckBox) findViewById(R.id.isPriorityCheckBox);
    //checkbox.setChecked(instance.isPriority);

    if (!(MainActivity.instance instanceof IssueTrackerConfig) || !MainActivity.instance.isAdmin) {
        //findViewById(R.id.isPriorityCheckBox).setVisibility(View.GONE);
    }
}

From source file:com.google.android.gcm.demo.ui.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    mLogger = new LoggingService.Logger(getActivity());

    mQuickTests = MainMenu.getTests(getActivity());
    mQuickTestsAdapter = new HintAdapter(getActivity(), android.R.layout.simple_spinner_item,
            new ArrayList<>(mQuickTests.keySet()), getString(R.string.home_quick_test_hint));
    mQuickTestsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    View view = inflater.inflate(R.layout.fragment_home, container, false);
    Spinner quickTests = (Spinner) view.findViewById(R.id.home_quick_test);
    quickTests.setPrompt(getString(R.string.home_quick_test_hint));
    quickTests.setAdapter(mQuickTestsAdapter);
    quickTests.setSelection(mQuickTestsAdapter.getCount());
    quickTests.setOnItemSelectedListener(this);

    view.findViewById(R.id.home_sender_id).setOnClickListener(this);
    view.findViewById(R.id.home_api_key).setOnClickListener(this);
    view.findViewById(R.id.home_destination).setOnClickListener(this);
    view.findViewById(R.id.home_submit).setOnClickListener(this);

    loadSavedState(savedState);//from  w ww .j a  va  2 s.c  om
    setValueFromFragmentState(view.findViewById(R.id.home_sender_id), SENDER_ID);
    setValueFromFragmentState(view.findViewById(R.id.home_api_key), API_KEY);
    setValueFromFragmentState(view.findViewById(R.id.home_destination), TOKEN);

    return view;
}