Example usage for android.widget Spinner getCount

List of usage examples for android.widget Spinner getCount

Introduction

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

Prototype

@Override
    public int getCount() 

Source Link

Usage

From source file:pl.selvin.android.listsyncsample.ui.EditItemActivity.java

void SetupSpinner(final int sid, final Spinner spinner) {
    for (int i = 0; i < spinner.getCount(); i++) {
        Cursor value = (Cursor) spinner.getItemAtPosition(i);
        int id = value.getInt(value.getColumnIndex(BaseColumns._ID));
        if (id == sid) {
            spinner.setSelection(i);/* w  w  w  . j a  va2  s.  c  om*/
            break;
        }
    }
}

From source file:org.appd.login.V_Role.java

/**
 * Load Spinner/*from w ww .j  av  a 2 s  . com*/
 * @author Yamel Senih 04/02/2013, 19:51:40
 * @param sp
 * @param id_ctx
 * @return
 * @return int
 */
private int setIDSpinner(Spinner sp, int id_ctx) {
    for (int i = 0; i < sp.getCount(); i++) {
        DisplaySpinner ds = (DisplaySpinner) sp.getItemAtPosition(i);
        if (ds.getID() == id_ctx) {
            sp.setSelection(i);
            return id_ctx;
        }
    }
    return 0;
}

From source file:com.misczak.joinmybridge.BridgeFragment.java

private int getSpinnerIndex(Spinner spinner, String tone) {
    int index = 0;

    for (int i = 0; i < spinner.getCount(); i++) {
        if (spinner.getItemAtPosition(i).equals(tone)) {
            index = i;/*from  www. j a  v  a2  s.c  o  m*/
        }
    }
    return index;
}

From source file:com.physphil.android.restaurantroulette.RestaurantFragment.java

/**
 * Gets position of genre in spinner/*from  ww w.  j  a  v a  2 s.  c om*/
 * @param spinner
 * @param genre
 * @return index of Genre in Spinner, returns index of Other if not found or if genre is null
 */
private int getIndex(Spinner spinner, String genre) {

    if (genre != null) {

        for (int i = 0; i < spinner.getCount(); i++) {

            if (spinner.getItemAtPosition(i).equals(genre)) {

                return i;
            }
        }
    }

    // Item not found, set as 'Other', which is always last position in spinner. Also set genre in Restaurant object as 'Other'
    int index = spinner.getCount() - 1;
    mRestaurant.setGenre((String) spinner.getItemAtPosition(index));
    return index;
}

From source file:com.ichi2.anki.multimediacard.activity.TranslationActivity.java

private int getSpinnerIndex(Spinner spinner, String myString) {

    int index = 0;

    for (int i = 0; i < spinner.getCount(); i++) {
        if (spinner.getItemAtPosition(i).equals(myString)) {
            index = i;// w  ww .j  av a2s .  c o m
        }
    }
    return index;
}

From source file:com.fullmeadalchemist.mustwatch.ui.batch.form.BatchFormFragment.java

private int getIndex(Spinner spinner, String myString) {
    int index = 0;
    for (int i = 0; i < spinner.getCount(); i++) {
        if (spinner.getItemAtPosition(i).toString().equalsIgnoreCase(myString)) {
            index = i;//from   ww  w. j a v  a 2  s.  co m
            break;
        }
    }
    return index;
}

From source file:com.redwoodsystems.android.apps.LightingListFragment.java

@Override
public void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    Log.d(TAG, "LightingListFragment.onResume called");

    //query settings
    Cursor settingsCursor = mSettingsDbHelper.fetchAllSettings();
    settings = mSettingsDbHelper.getSettings(settingsCursor);

    //Spinner//from   www.j a v  a  2  s.c om
    setupLocationSpinner();

    //Set Spinner to stored value if present
    //check if stored value still exists. It could have been deleted
    int storedLocationId = settings.getLastLocationId();
    if (storedLocationId > -1) {
        Spinner spinner = (Spinner) getActivity().findViewById(R.id.locationSpinner);
        int pos = -1;
        for (int i = 0; i < spinner.getCount(); i++) {
            Cursor c = (Cursor) spinner.getItemAtPosition(i);
            int locId = mLocationDbHelper.getLocationId(c);
            if (locId == storedLocationId) {
                pos = i;
                Log.d(TAG, "setting spinner to stored value = " + Integer.toString(storedLocationId));
                spinner.setSelection(i);
                mCurrentLocation = mLocationDbHelper.getLocation(c);
            }
        }
    }

}

From source file:org.eyeseetea.malariacare.fragments.CreateSurveyFragment.java

private int getIndex(Spinner spinner, String myString) {
    int index = 0;
    for (int i = 0; i < spinner.getCount(); i++) {
        Object objectRow = spinner.getItemAtPosition(i);
        String value = "";
        if (objectRow instanceof Program) {
            value = ((Program) objectRow).getName();
        }//from w ww  .  ja  v a  2  s  .  c  o  m
        if (objectRow instanceof OrgUnit) {
            value = ((OrgUnit) objectRow).getName();
        }
        if (value.equalsIgnoreCase(myString)) {
            index = i;
            break;
        }
    }
    return index;
}

From source file:com.prevas.redmine.NewIssueActivity.java

private void createIssue() {
    if (isEmpty(mSubjectEditText)) {
        Toast.makeText(this, "Subject can't be empty", Toast.LENGTH_LONG).show();
        return;/*from www . java  2 s .c  om*/
    }

    Issue issue = new Issue();
    if (-1 != mParentId) {
        issue.setParentId(mParentId);
    }

    // Subject
    issue.setSubject(mSubjectEditText.getText().toString());

    // Description
    if (!isEmpty(mDescriptionEditText)) {
        issue.setDescription(mDescriptionEditText.getText().toString());
    }

    // Notes
    if (!isEmpty(mNotesEditText)) {
        issue.setNotes(mNotesEditText.getText().toString());
    }

    // Estimated hours
    String hoursString = mEstimatedHoursEditText.getText().toString();
    if (null != hoursString && hoursString.length() > 0) {
        try {
            float estimatedHours = Float.parseFloat(hoursString);
            issue.setEstimatedHours(estimatedHours);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Start date
    if (null != mStartDate) {
        issue.setStartDate(mStartDate);
    }

    // Due date
    if (null != mDueDate) {
        issue.setStartDate(mDueDate);
    }

    // Percent done
    if (-1 != mPercentDone) {
        issue.setDoneRatio(mPercentDone);
    }

    // Tracker
    Spinner trackerSpinner = (Spinner) findViewById(R.id.spin_Tracker);
    Tracker tracker = mTrackerAdapter.getItem(trackerSpinner.getSelectedItemPosition());
    issue.setTracker(tracker);

    // Status
    Spinner statusSpinner = (Spinner) findViewById(R.id.spin_Status);
    Integer statusId = (int) mStatusAdapter.getItemId(statusSpinner.getSelectedItemPosition());
    issue.setStatusId(statusId);

    // Priority
    Spinner prioritySpinner = (Spinner) findViewById(R.id.spin_Priority);
    //String priorityString = mPrioritiesAdapter.getItem(prioritySpinner.getSelectedItemPosition());
    //Integer priorityId = mPriorityMap.get(priorityString);
    Integer priorityId = (int) mPrioritiesAdapter.getItemId(prioritySpinner.getSelectedItemPosition());
    issue.setPriorityId(priorityId);

    // Version
    Spinner versionSpinner = (Spinner) findViewById(R.id.spin_Version);
    if (versionSpinner.getCount() > 0) {
        Version version = mVersionAdapter.getItem(versionSpinner.getSelectedItemPosition());
        issue.setTargetVersion(version);
    }

    // Assignee
    Spinner assigneeSpinner = (Spinner) findViewById(R.id.spin_Assignee);
    if (assigneeSpinner.getCount() > 0) {
        String userString = mAssigneeAdapter.getItem(assigneeSpinner.getSelectedItemPosition());
        if (userString.equals("--")) {
            issue.setAssignee(null);
        } else {
            issue.setAssignee(getUserFromMemberList(userString));
        }
    }

    // Create issue
    try {
        String projectKey = PrevasRedmine.getCurrentProjectIdentifier();
        //issue.setStartDate(null);
        Issue createdIssue = PrevasRedmine.m_redmineManager.createIssue(projectKey, issue);
        if (null != createdIssue) {
            PrevasRedmine.addNewIssueToMap(createdIssue);
            //Toast.makeText(this, "Issue Created !", Toast.LENGTH_LONG).show();
            //setResult(Activity.RESULT_OK);
        }
    } catch (RedmineException e) {
        e.printStackTrace();
    }

}

From source file:org.lyricue.android.BibleFragment.java

void select_verse(String verse) {
    Log.i(TAG, "Select Verse " + verse);
    Spinner spin = (Spinner) v.findViewById(R.id.spinBibleBook);
    String[] tokens = verse.split("[-:]");
    String bible = tokens[0];//from  w w w  .  j a  v a  2  s .c  o  m
    int chapter = Integer.parseInt(tokens[1]);
    int start_verse = Integer.parseInt(tokens[2]);
    int end_verse = Integer.parseInt(tokens[4]);
    for (int i = 0; i < spin.getCount(); i++) {
        if (spin.getItemAtPosition(i).toString().equals(bible)) {
            spin.setSelection(i);
        }
    }
    spin = (Spinner) v.findViewById(R.id.spinBibleChapter);
    spin.setSelection(chapter - 1);
    spin = (Spinner) v.findViewById(R.id.spinBibleVerseStart);
    spin.setSelection(start_verse - 1);
    spin = (Spinner) v.findViewById(R.id.spinBibleVerseEnd);
    spin.setSelection(end_verse - 1);
}