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:com.bangalore.barcamp.activity.ShareActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share_screen);
    mDrawerToggle = BCBFragmentUtils.setupActionBar(this, "Share");

    // BCBUtils.createActionBarOnActivity(this);
    // BCBUtils.addNavigationActions(this);
    ((EditText) findViewById(R.id.editText1)).addTextChangedListener(new TextWatcher() {

        @Override/*from  w  ww  .  j av a2s  .  co  m*/
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

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

        }

        @Override
        public void afterTextChanged(Editable s) {
            ((TextView) findViewById(R.id.charsLeftTextView)).setText("Chars left: " + (140 - s.length() - 7));
        }
    });
    if (getIntent().hasExtra(SHARE_STRING)) {
        ((EditText) findViewById(R.id.editText1)).setText(getIntent().getStringExtra(SHARE_STRING));
    }
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    final PackageManager pm = getPackageManager();
    final Spinner spinner = (Spinner) findViewById(R.id.shareTypeSpinner);
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
    String selectedItem = BCBSharedPrefUtils.getShareSettings(getApplicationContext());
    int selectedPos = -1;
    for (ResolveInfo info : matches) {
        adapter.add(info.loadLabel(pm));
        if (selectedItem.equals(info.loadLabel(pm))) {
            selectedPos = matches.indexOf(info);
        }
    }
    spinner.setAdapter(adapter);

    if (selectedPos != -1) {
        spinner.setSelected(true);
        spinner.setSelection(selectedPos);
    }
    ((TextView) findViewById(R.id.charsLeftTextView)).setText("Chars left: 140");
    ((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            int appSelectedPos = spinner.getSelectedItemPosition();
            ResolveInfo info = matches.get(appSelectedPos);
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);

            BCBSharedPrefUtils.setShareSettings(getApplicationContext(), (String) info.loadLabel(pm));
            intent.putExtra(Intent.EXTRA_TEXT,
                    ((EditText) findViewById(R.id.editText1)).getText().toString() + " #barcampblr");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(intent);
            finish();

        }
    });

    BCBFragmentUtils.addNavigationActions(this);
    supportInvalidateOptionsMenu();
    Tracker t = ((BarcampBangalore) getApplication()).getTracker();

    // Set screen name.
    t.setScreenName(this.getClass().getName());

    // Send a screen view.
    t.send(new HitBuilders.AppViewBuilder().build());

}

From source file:com.ncode.android.apps.schedo.ui.MyScheduleActivity.java

private void trySetUpActionBarSpinner() {
    Toolbar toolbar = getActionBarToolbar();
    if (mSpinnerConfigured || mSchedMetadata == null || toolbar == null) {
        // already done it, or not ready yet, or don't need to do
        LOGD(TAG, "Not configuring Action Bar spinner.");
        return;/* w  ww  . j ava 2  s.c om*/
    }

    LOGD(TAG, "Configuring Action Bar spinner.");
    mSpinnerConfigured = true;
    mTopLevelSpinnerAdapter.clear();
    mTopLevelSpinnerAdapter.addItem("", getString(R.string.all_events), false, 0);

    int itemToSelect = -1;

    Collection<MyScheduleMetadata.MySchedEvent> events = mSchedMetadata.getMyScheduleEvents();
    if (events != null) {
        //mTopLevelSpinnerAdapter.addHeader(categoryTitle);
        for (MyScheduleMetadata.MySchedEvent e : events) {
            LOGD(TAG, "Adding item to spinner: " + e.getId() + " --> " + e.getTitle());
            int eventColor = e.getColor() > 0 ? e.getColor() : 0;
            mTopLevelSpinnerAdapter.addItem(e.getId(), e.getTitle(), true, eventColor);
            if (!TextUtils.isEmpty(mFilterSchedsToRestore) && e.getId().equals(mFilterSchedsToRestore)) {
                mFilterSchedsToRestore = null;
                itemToSelect = mTopLevelSpinnerAdapter.getCount() - 1;
            }
        }
    } else {
        LOGW(TAG, "No events scheduled");
    }

    mFilterSchedsToRestore = null;

    View spinnerContainer = LayoutInflater.from(this).inflate(R.layout.actionbar_spinner, toolbar, false);
    ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    toolbar.addView(spinnerContainer, lp);

    Spinner spinner = (Spinner) spinnerContainer.findViewById(R.id.actionbar_spinner);
    spinner.setAdapter(mTopLevelSpinnerAdapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> spinner, View view, int position, long itemId) {
            onTopLevelEventSelected(mTopLevelSpinnerAdapter.getTag(position));
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    if (itemToSelect >= 0) {
        LOGD(TAG, "Restoring item selection to primary spinner: " + itemToSelect);
        spinner.setSelection(itemToSelect);
    }

    updateHeaderColor();
    //showSecondaryFilters();
}

From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java

/**
 * @param fieldTable//from   w  ww  . j  a  v a  2 s .  co  m
 * @param nameOfField
 * @param field
 */
private void addConflictRow(TableLayout fieldTable, final String nameOfField, final String fieldLocal,
        final String fieldRemote) {
    if (mCurrentLocal == null || mCurrentSugar == null)
        return;
    // String fieldLocal = mCurrentLocal.get(nameOfField);
    // String fieldRemote = mCurrentSugar.get(nameOfField);
    TableRow row = new TableRow(this);
    final Spinner sourceSelect = new Spinner(this);
    sourceSelect.setBackgroundResource(R.drawable.black_underline);
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, this.getResources().getStringArray(R.array.conflict_sources));
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sourceSelect.setAdapter(spinnerArrayAdapter);
    // Open the spinner when pressing any of the text fields
    OnClickListener spinnerOpener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            sourceSelect.performClick();
        }
    };
    row.addView(sourceSelect);
    fieldTable.addView(row);
    row = new TableRow(this);
    TextView fieldName = new TextView(this);
    int stringId = this.getResources().getIdentifier(nameOfField, "string", this.getPackageName());
    fieldName.setText(this.getString(stringId));
    fieldName.setTextSize(16);
    fieldName.setPadding(fieldName.getPaddingLeft(), fieldName.getPaddingTop(),
            fieldName.getPaddingRight() + 10, fieldName.getPaddingBottom());
    fieldName.setOnClickListener(spinnerOpener);
    row.addView(fieldName);
    final TextView fieldValueLocal = new TextView(this);
    fieldValueLocal.setText(fieldLocal);
    fieldValueLocal.setTextSize(16);
    row.addView(fieldValueLocal);
    fieldValueLocal.setOnClickListener(spinnerOpener);

    fieldTable.addView(row);
    row = new TableRow(this);
    row.addView(new TextView(this));// add dummy control
    final TextView fieldValueRemote = new TextView(this);
    fieldValueRemote.setText(fieldRemote);
    fieldValueRemote.setTextSize(16);

    fieldValueRemote.setOnClickListener(spinnerOpener);
    row.addView(fieldValueRemote);
    sourceSelect.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected);
                fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected);
                resolvedContacts[mPosResolved].set(nameOfField, fieldLocal);
            } else {
                fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected);
                fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected);
                resolvedContacts[mPosResolved].set(nameOfField, fieldRemote);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> view) {
        }
    });
    row.setPadding(row.getLeft(), row.getTop() + 5, row.getRight(), row.getBottom() + 10);
    // Restore appropiate selections according to resolved contact
    if (resolvedContacts[mPosResolved].get(nameOfField).equals(fieldLocal)) {
        sourceSelect.setSelection(0);
    } else {
        sourceSelect.setSelection(1);
    }
    fieldTable.addView(row);
}

From source file:at.wada811.imageslider.DebugFragment.java

private void initAnimation(Spinner animationSpinner) {
    List<InOutAnimationList> inOutAnimationLists = Arrays.asList(InOutAnimationList.values());
    ArrayList<InOutAnimation> tempInOutAnimations = new ArrayList<InOutAnimation>();
    for (InOutAnimationList inOutAnimationList : inOutAnimationLists) {
        InOutAnimation inOutAnimation = inOutAnimationList.getInOutAnimation(getActivity());
        tempInOutAnimations.add(inOutAnimation);
    }/*from  ww w  . j  a  va2 s  .co m*/
    final ArrayList<InOutAnimation> inOutAnimations = new ArrayList<InOutAnimation>(tempInOutAnimations);
    AnimationAdapter adapter = new AnimationAdapter(getActivity(), inOutAnimations);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    animationSpinner.setAdapter(adapter);
    animationSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            InOutAnimation inOutAnimation = inOutAnimations.get(position);
            mCallback.setInOutAnimation(inOutAnimation);
        }

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

        }
    });
}

From source file:com.cmput301w17t07.moody.EditMoodActivity.java

/**
 * display the attributes of the mood that was selected to view <br>
 * Spinner dropdown logic taken from <br>
 * link: http://stackoverflow.com/questions/13377361/how-to-create-a-drop-down-list <br>
 * Author: Nicolas Tyler, 2013/07/15 8:47 <br>
 * taken by Xin Huang 2017-03-04 15:30 (used and swith function written by Nick 2017/03/12 14:30) <br>
 */// w  w w  . j a va 2s.c om
private void displayAttributes() {
    final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation);
    if (address == null) {
        deleteLocation.setVisibility(View.INVISIBLE);
        deleteLocation.setEnabled(false);
    }

    Spinner dropdown = (Spinner) findViewById(R.id.editEmotion);

    String[] items = new String[] { "anger", "confusion", "disgust", "fear", "happiness", "sadness", "shame",
            "surprise" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
            items);
    dropdown.setAdapter(adapter);

    switch (editMood.getFeeling()) {
    case "anger":
        dropdown.setSelection(0);
        break;
    case "confusion":
        dropdown.setSelection(1);
        break;
    case "disgust":
        dropdown.setSelection(2);
        break;
    case "fear":
        dropdown.setSelection(3);
        break;
    case "happiness":
        dropdown.setSelection(4);
        break;
    case "sadness":
        dropdown.setSelection(5);
        break;
    case "shame":
        dropdown.setSelection(6);
        break;
    case "surprise":
        dropdown.setSelection(7);
        break;

    }
    dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            EmotionText = parent.getItemAtPosition(position).toString();
            editMood.setFeeling(EmotionText);
            TextView sizeView = (TextView) findViewById(R.id.editSocialText);
            sizeView.setText("Feeling " + EmotionText + " " + SocialSituation);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            Toast.makeText(EditMoodActivity.this, "Please pick a feeling!", Toast.LENGTH_SHORT).show();
        }
    });

    Spinner dropdown_SocialSituation = (Spinner) findViewById(R.id.editSocialSituation);
    String[] item_SocialSituation = new String[] { "", "alone", "with one other person", "with two people",
            "with several people", "with a crowd" };
    ArrayAdapter<String> adapter_SocialSituation = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_dropdown_item, item_SocialSituation);
    dropdown_SocialSituation.setAdapter(adapter_SocialSituation);
    switch (editMood.getSocialSituation()) {
    case "alone":
        dropdown_SocialSituation.setSelection(1);
        break;
    case "with one other person":
        dropdown_SocialSituation.setSelection(2);
        break;
    case "with two people":
        dropdown_SocialSituation.setSelection(3);
        break;
    case "with several people":
        dropdown_SocialSituation.setSelection(4);
        break;
    case "with a crowd":
        dropdown_SocialSituation.setSelection(5);
        break;

    }

    dropdown_SocialSituation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            SocialSituation = parent.getItemAtPosition(position).toString();
            editMood.setSocialSituation(SocialSituation);
            TextView sizeView = (TextView) findViewById(R.id.editSocialText);
            sizeView.setText("Feeling " + EmotionText + " " + SocialSituation);
        }

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

    Description = (EditText) findViewById(R.id.editDescription);
    Description.setText(editMood.getMoodMessage());
    editBitmapImage = editMood.decodeImage();
    if (editBitmapImage != null) {
        image.setImageBitmap(editBitmapImage);
    } else {
        image.setImageBitmap(bitmapImage);
    }
}

From source file:com.todoroo.astrid.repeats.RepeatControlSet.java

@Nullable
@Override/*from   w w w. j  a va  2s . c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    if (savedInstanceState != null) {
        recurrence = savedInstanceState.getString(EXTRA_RECURRENCE);
        repeatUntilValue = savedInstanceState.getLong(EXTRA_REPEAT_UNTIL);
        repeatAfterCompletion = savedInstanceState.getBoolean(EXTRA_REPEAT_AFTER_COMPLETION);
    }

    dialogView = inflater.inflate(R.layout.control_set_repeat, null);
    value = (Button) dialogView.findViewById(R.id.repeatValue);
    Spinner interval = (Spinner) dialogView.findViewById(R.id.repeatInterval);
    ArrayAdapter<String> intervalAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.repeat_interval));
    intervalAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    interval.setAdapter(intervalAdapter);
    Spinner type = (Spinner) dialogView.findViewById(R.id.repeatType);
    ArrayAdapter<String> typeAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.repeat_type));
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    type.setAdapter(typeAdapter);
    type.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            repeatAfterCompletion = position == TYPE_COMPLETION_DATE;
        }

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

        }
    });
    daysOfWeekContainer = (LinearLayout) dialogView.findViewById(R.id.repeatDayOfWeekContainer);
    repeatUntil = (Spinner) dialogView.findViewById(R.id.repeat_until);
    repeatUntilAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, repeatUntilOptions);
    repeatUntilAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    repeatUntil.setAdapter(repeatUntilAdapter);
    // set up days of week
    DateFormatSymbols dfs = new DateFormatSymbols();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
    CompoundButton[] daysOfWeek = new CompoundButton[7];
    for (int i = 0; i < 7; i++) {
        final int index = i;
        CheckBox checkBox = (CheckBox) daysOfWeekContainer.getChildAt(i);
        checkBox.setOnCheckedChangeListener(
                (buttonView, isChecked1) -> RepeatControlSet.this.isChecked[index] = isChecked1);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        checkBox.setText(dfs.getShortWeekdays()[dayOfWeek].substring(0, 1));
        daysOfWeek[i] = checkBox;
        weekdays[i] = Weekday.values()[dayOfWeek - 1];
        calendar.add(Calendar.DATE, 1);
    }

    // set up listeners
    value.setOnClickListener(v -> repeatValueClick());

    setRepeatValue(1);
    interval.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View view, int position, long id) {
            daysOfWeekContainer.setVisibility(position == INTERVAL_WEEKS ? View.VISIBLE : View.GONE);
            intervalValue = position;
        }

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

    setRepeatUntilValue(repeatUntilValue);
    repeatUntil.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (repeatUntilOptions.size() == 2) {
                if (i == 0) {
                    setRepeatUntilValue(0);
                } else {
                    repeatUntilClick();
                }
            } else {
                if (i == 1) {
                    setRepeatUntilValue(0);
                } else if (i == 2) {
                    repeatUntilClick();
                }
            }
        }

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

    daysOfWeekContainer.setVisibility(View.GONE);
    type.setSelection(repeatAfterCompletion ? TYPE_COMPLETION_DATE : TYPE_DUE_DATE);
    doRepeat = !Strings.isNullOrEmpty(recurrence);
    if (doRepeat) {
        // read recurrence rule
        try {
            RRule rrule = new RRule(recurrence);

            setRepeatValue(rrule.getInterval());

            for (WeekdayNum day : rrule.getByDay()) {
                for (int i = 0; i < 7; i++) {
                    if (weekdays[i].equals(day.wday)) {
                        daysOfWeek[i].setChecked(true);
                    }
                }
            }

            switch (rrule.getFreq()) {
            case DAILY:
                intervalValue = INTERVAL_DAYS;
                break;
            case WEEKLY:
                intervalValue = INTERVAL_WEEKS;
                break;
            case MONTHLY:
                intervalValue = INTERVAL_MONTHS;
                break;
            case HOURLY:
                intervalValue = INTERVAL_HOURS;
                break;
            case MINUTELY:
                intervalValue = INTERVAL_MINUTES;
                break;
            case YEARLY:
                intervalValue = INTERVAL_YEARS;
                break;
            default:
                Timber.e(new Exception("Unhandled rrule frequency: " + recurrence), "repeat-unhandled-rule");
            }
            interval.setSelection(intervalValue);

        } catch (Exception e) {
            // invalid RRULE
            recurrence = ""; //$NON-NLS-1$
            Timber.e(e, e.getMessage());
        }
    }
    refreshDisplayView();
    return view;
}

From source file:com.cmput301w17t07.moody.CreateMoodActivity.java

/**
 * displayAttributes method used when the user gets back from the "Map" display
 * and displays the changed spinner attributes.
 * <br>//from  w w  w. j a  va  2s .  c  o m
 * Spinner dropdown logic taken from <br>
 * link: http://stackoverflow.com/questions/13377361/how-to-create-a-drop-down-listm <br>
 * Author: Nicolas Tyler, 2013/07/15 8:47 <br>
 * taken by Xin Huang 2017-03-04 15:30 (used and switch function written by Nick 2017/03/12 14:30) <br>
 */
private void displayAttributes() {
    Spinner dropdown = (Spinner) findViewById(R.id.Emotion);
    String[] items = new String[] { "anger", "confusion", "disgust", "fear", "happiness", "sadness", "shame",
            "surprise" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
            items);
    dropdown.setAdapter(adapter);

    switch (tempMood.getFeeling()) {
    case "anger":
        dropdown.setSelection(0);
        break;
    case "confusion":
        dropdown.setSelection(1);
        break;
    case "disgust":
        dropdown.setSelection(2);
        break;
    case "fear":
        dropdown.setSelection(3);
        break;
    case "happiness":
        dropdown.setSelection(4);
        break;
    case "sadness":
        dropdown.setSelection(5);
        break;
    case "shame":
        dropdown.setSelection(6);
        break;
    case "surprise":
        dropdown.setSelection(7);
        break;

    }
    dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            EmotionText = parent.getItemAtPosition(position).toString();
            tempMood.setFeeling(EmotionText);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            Toast.makeText(CreateMoodActivity.this, "Please pick a feeling!", Toast.LENGTH_SHORT).show();
        }
    });

    Spinner dropdown_SocialSituation = (Spinner) findViewById(R.id.SocialSituation);
    String[] item_SocialSituation = new String[] { "", "alone", "with one other person", "with two people",
            "with several people", "with a crowd" };
    ArrayAdapter<String> adapter_SocialSituation = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_dropdown_item, item_SocialSituation);
    dropdown_SocialSituation.setAdapter(adapter_SocialSituation);
    switch (tempMood.getSocialSituation()) {
    case "alone":
        dropdown_SocialSituation.setSelection(1);
        break;
    case "with one other person":
        dropdown_SocialSituation.setSelection(2);
        break;
    case "with two people":
        dropdown_SocialSituation.setSelection(3);
        break;
    case "with several people":
        dropdown_SocialSituation.setSelection(4);
        break;
    case "with a crowd":
        dropdown_SocialSituation.setSelection(5);
        break;

    }

    dropdown_SocialSituation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            SocialSituation = parent.getItemAtPosition(position).toString();
            tempMood.setSocialSituation(SocialSituation);
            TextView sizeView = (TextView) findViewById(R.id.SocialText);
            sizeView.setText("  " + SocialSituation);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            Toast.makeText(CreateMoodActivity.this, "Please pick a feeling!", Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:com.duongnx.ndk.examples.activities.NativeAudioActivity.java

/**
 * Called when the activity is first created.
 *//*from  w ww .  j av a  2  s  . c  o m*/
@Override
@TargetApi(17)
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_native_audio);
    setTitle(Defines.NATIVE_AUDIO);
    assetManager = getAssets();

    // initialize native audio system
    createEngine();

    int sampleRate = 0;
    int bufSize = 0;
    /*
     * retrieve fast audio path sample rate and buf size; if we have it, we pass to native
     * side to create a player with fast audio enabled [ fast audio == low latency audio ];
     * IF we do not have a fast audio path, we pass 0 for sampleRate, which will force native
     * side to pick up the 8Khz sample rate.
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        String nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
        sampleRate = Integer.parseInt(nativeParam);
        nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
        bufSize = Integer.parseInt(nativeParam);
    }
    createBufferQueueAudioPlayer(sampleRate, bufSize);

    // initialize URI spinner
    Spinner uriSpinner = (Spinner) findViewById(R.id.uri_spinner);
    ArrayAdapter<CharSequence> uriAdapter = ArrayAdapter.createFromResource(this, R.array.uri_spinner_array,
            android.R.layout.simple_spinner_item);
    uriAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    uriSpinner.setAdapter(uriAdapter);
    uriSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            URI = parent.getItemAtPosition(pos).toString();
        }

        public void onNothingSelected(AdapterView parent) {
            URI = null;
        }

    });

    // initialize button click handlers

    ((Button) findViewById(R.id.hello)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // ignore the return value
            selectClip(CLIP_HELLO, 5);
        }
    });

    ((Button) findViewById(R.id.android)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // ignore the return value
            selectClip(CLIP_ANDROID, 7);
        }
    });

    ((Button) findViewById(R.id.sawtooth)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // ignore the return value
            selectClip(CLIP_SAWTOOTH, 1);
        }
    });

    ((Button) findViewById(R.id.reverb)).setOnClickListener(new OnClickListener() {
        boolean enabled = false;

        public void onClick(View view) {
            enabled = !enabled;
            if (!enableReverb(enabled)) {
                enabled = !enabled;
            }
        }
    });

    ((Button) findViewById(R.id.embedded_soundtrack)).setOnClickListener(new OnClickListener() {
        boolean created = false;

        public void onClick(View view) {
            if (!created) {
                created = createAssetAudioPlayer(assetManager, "background.mp3");
            }
            if (created) {
                isPlayingAsset = !isPlayingAsset;
                setPlayingAssetAudioPlayer(isPlayingAsset);
            }
        }
    });

    // native uriPlayer is broken in android 21 and over, internal bug id: b/29321867
    // will re-open after it is fixed in later OSes
    if (Build.VERSION.SDK_INT <= 19) {
        ((Button) findViewById(R.id.uri_soundtrack)).setOnClickListener(new OnClickListener() {
            boolean created = false;

            public void onClick(View view) {
                if (!created && URI != null) {
                    created = createUriAudioPlayer(URI);
                }
            }
        });

        ((Button) findViewById(R.id.pause_uri)).setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                setPlayingUriAudioPlayer(false);
            }
        });

        ((Button) findViewById(R.id.play_uri)).setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                setPlayingUriAudioPlayer(true);
            }
        });

        ((Button) findViewById(R.id.loop_uri)).setOnClickListener(new OnClickListener() {
            boolean isLooping = false;

            public void onClick(View view) {
                isLooping = !isLooping;
                setLoopingUriAudioPlayer(isLooping);
            }
        });

        ((Button) findViewById(R.id.mute_left_uri)).setOnClickListener(new OnClickListener() {
            boolean muted = false;

            public void onClick(View view) {
                muted = !muted;
                setChannelMuteUriAudioPlayer(0, muted);
            }
        });

        ((Button) findViewById(R.id.mute_right_uri)).setOnClickListener(new OnClickListener() {
            boolean muted = false;

            public void onClick(View view) {
                muted = !muted;
                setChannelMuteUriAudioPlayer(1, muted);
            }
        });

        ((Button) findViewById(R.id.solo_left_uri)).setOnClickListener(new OnClickListener() {
            boolean soloed = false;

            public void onClick(View view) {
                soloed = !soloed;
                setChannelSoloUriAudioPlayer(0, soloed);
            }
        });

        ((Button) findViewById(R.id.solo_right_uri)).setOnClickListener(new OnClickListener() {
            boolean soloed = false;

            public void onClick(View view) {
                soloed = !soloed;
                setChannelSoloUriAudioPlayer(1, soloed);
            }
        });

        ((Button) findViewById(R.id.mute_uri)).setOnClickListener(new OnClickListener() {
            boolean muted = false;

            public void onClick(View view) {
                muted = !muted;
                setMuteUriAudioPlayer(muted);
            }
        });

        ((Button) findViewById(R.id.enable_stereo_position_uri)).setOnClickListener(new OnClickListener() {
            boolean enabled = false;

            public void onClick(View view) {
                enabled = !enabled;
                enableStereoPositionUriAudioPlayer(enabled);
            }
        });

        ((Button) findViewById(R.id.channels_uri)).setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                if (numChannelsUri == 0) {
                    numChannelsUri = getNumChannelsUriAudioPlayer();
                }
                Toast.makeText(NativeAudioActivity.this, "Channels: " + numChannelsUri, Toast.LENGTH_SHORT)
                        .show();
            }
        });

        ((SeekBar) findViewById(R.id.volume_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            int lastProgress = 100;

            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) {
                    throw new AssertionError();
                }
                lastProgress = progress;
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                int attenuation = 100 - lastProgress;
                int millibel = attenuation * -50;
                setVolumeUriAudioPlayer(millibel);
            }
        });

        ((SeekBar) findViewById(R.id.pan_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            int lastProgress = 100;

            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) {
                    throw new AssertionError();
                }
                lastProgress = progress;
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                int permille = (lastProgress - 50) * 20;
                setStereoPositionUriAudioPlayer(permille);
            }
        });
    } else {
        int[] uriIds = { R.id.uri_soundtrack, R.id.pause_uri, R.id.play_uri, R.id.loop_uri, R.id.mute_left_uri,
                R.id.mute_right_uri, R.id.solo_left_uri, R.id.solo_right_uri, R.id.mute_uri,
                R.id.enable_stereo_position_uri, R.id.channels_uri, R.id.volume_uri, R.id.pan_uri,
                R.id.uri_spinner, };
        for (int id : uriIds)
            findViewById(id).setVisibility(View.GONE);
    }

    ((Button) findViewById(R.id.record)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            int status = ActivityCompat.checkSelfPermission(NativeAudioActivity.this,
                    Manifest.permission.RECORD_AUDIO);
            if (status != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(NativeAudioActivity.this,
                        new String[] { Manifest.permission.RECORD_AUDIO }, AUDIO_ECHO_REQUEST);
                return;
            }
            recordAudio();
        }
    });

    ((Button) findViewById(R.id.playback)).setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // ignore the return value
            selectClip(CLIP_PLAYBACK, 3);
        }
    });

}

From source file:org.akvo.caddisfly.ui.activity.MainActivity.java

private void setupActionBarSpinner() {
    ActionBar ab = getActionBar();/*from  ww  w  .  j  a  v  a  2 s  .  com*/

    ArrayList<TestInfo> tests = null;
    try {
        tests = JsonUtils.loadTests(FileUtils.readRawTextFile(this, R.raw.tests_json));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    mTopLevelSpinnerAdapter.clear();
    MainApp mainApp = (MainApp) getApplicationContext();

    int selectedIndex = 0;
    int index = 0;
    assert tests != null;
    for (TestInfo test : tests) {
        mTopLevelSpinnerAdapter.addItem(test.getCode(), test.getName());
        if (test.getCode().equalsIgnoreCase(mainApp.currentTestInfo.getCode())) {
            selectedIndex = index;
        }
        index++;
    }

    @SuppressLint("InflateParams")
    View spinnerContainer = LayoutInflater.from(this).inflate(R.layout.actionbar_spinner, null);
    ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    assert ab != null;
    ab.setCustomView(spinnerContainer, lp);

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

    spinner.setSelection(selectedIndex);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> spinner, View view, int position, long itemId) {
            MainApp mainApp = (MainApp) getApplicationContext();
            String testType = mTopLevelSpinnerAdapter.getTag(position);
            mainApp.setSwatches(testType);
            mCalibrateFragment.dataChanged();
        }

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