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.skobka.tram.ui.activity.ScheduleActivity.java

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w w  w .  ja v a  2s . co  m
    //noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    route = getIntent().getParcelableExtra(EXTRA_ROUTE);
    day = getIntent().getParcelableExtra(EXTRA_DAY);
    direction = getIntent().getParcelableExtra(EXTRA_DIRECTION);

    // Setup spinner
    spinnerAdapter = new SpinnerAdapter(this);
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    spinner.setAdapter(spinnerAdapter);

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // When the given dropdown item is selected, show its contents in the
            // container view.
            Station station = spinnerAdapter.getItem(position);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, PlaceholderFragment.newInstance(station)).commit();
        }

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

    loader = loaderFactory.create(null, new ScheduleLoadingListener() {
        @Override
        public void onScheduleLoaded(final Schedule schedule) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    spinnerAdapter.addAll(schedule.getStationList());
                    spinnerAdapter.notifyDataSetChanged();
                }
            });
        }

        @Override
        public void onFailure() {
            Toast.makeText(getApplicationContext(), "? ?  ",
                    Toast.LENGTH_SHORT).show();
        }
    });

    loader.loadSchedule(route, direction, day);
    setTitle(route.getFullTitle() + ", " + day.getTitle());
}

From source file:self.yue.vehicletracker.ui.main.MainFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_main, menu);
    mSpinnerItem = menu.findItem(R.id.action_number_plate);

    Spinner spinnerNumberPlate = (Spinner) MenuItemCompat.getActionView(mSpinnerItem);

    spinnerNumberPlate.setAdapter(mVehiclesAdapter);

    ApiProvider.getInstance().getUserVehicles(CacheHelper.getInstance().getCurrentUser().getEmail(),
            new OnServerResponseListener<List<Vehicle>>() {
                @Override/*  ww w .  j a  va2 s .c  o m*/
                public void onSuccess(List<Vehicle> data) {
                    for (Vehicle vehicle : data) {
                        mVehiclesAdapter.add(vehicle.licensePlate);
                    }
                    mVehiclesAdapter.notifyDataSetChanged();

                    if (data.size() > 0) {
                        mLicensePlate = data.get(0).licensePlate;
                        transferDataToPage();
                    }
                }

                @Override
                public void onFail(Throwable t) {

                }
            });

    spinnerNumberPlate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mLicensePlate = mVehiclesAdapter.getItem(position);
            transferDataToPage();
        }

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

        }
    });
}

From source file:com.meiste.greg.ptw.tab.QuestionsForm.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    Util.log("QuestionsForm: onCreateView");

    final String json = getArguments().getString(RACE_QUESTIONS);
    if (json == null) {
        return null;
    }//from  w  ww.j  a  v  a  2  s.c  o m
    final RaceQuestions rq = RaceQuestions.fromJson(json);
    final View v = inflater.inflate(R.layout.questions_form, container, false);

    final Spinner winner = (Spinner) v.findViewById(R.id.winner);
    winner.setAdapter(new DriverAdapter(getActivity(), rq.drivers));
    winner.setOnItemSelectedListener(new WinnerSelectedListener());

    final TextView q2 = (TextView) v.findViewById(R.id.question2);
    q2.setText(getActivity().getString(R.string.questions_2, rq.q2));

    final Spinner a2 = (Spinner) v.findViewById(R.id.question2a);
    final ArrayAdapter<CharSequence> a2_adapter = new ArrayAdapter<CharSequence>(getActivity(),
            android.R.layout.simple_spinner_item, rq.a2);
    a2_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    a2.setAdapter(a2_adapter);
    a2.setOnItemSelectedListener(new A2SelectedListener());

    final TextView q3 = (TextView) v.findViewById(R.id.question3);
    q3.setText(getActivity().getString(R.string.questions_3, rq.q3));

    final Spinner a3 = (Spinner) v.findViewById(R.id.question3a);
    final ArrayAdapter<CharSequence> a3_adapter = new ArrayAdapter<CharSequence>(getActivity(),
            android.R.layout.simple_spinner_item, rq.a3);
    a3_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    a3.setAdapter(a3_adapter);
    a3.setOnItemSelectedListener(new A3SelectedListener());

    final Spinner mostlaps = (Spinner) v.findViewById(R.id.mostlaps);
    mostlaps.setAdapter(new DriverAdapter(getActivity(), rq.drivers));
    mostlaps.setOnItemSelectedListener(new MostLapsSelectedListener());

    final Spinner numleaders = (Spinner) v.findViewById(R.id.numleaders);
    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.num_leaders, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    numleaders.setAdapter(adapter);
    numleaders.setOnItemSelectedListener(new NumLeadersSelectedListener());

    final Button send = (Button) v.findViewById(R.id.send);
    send.setOnClickListener(this);

    return v;
}

From source file:com.androguide.honamicontrol.kernel.KernelFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.profiles, menu);
    MenuItem item = menu.findItem(R.id.profile_spinner);
    View spinner = item != null ? item.getActionView() : null;
    if (spinner instanceof android.widget.Spinner) {
        final SharedPreferences profilePrefs = super.getActivity().getSharedPreferences("PROFILES", 0);
        Spinner profiles = (Spinner) spinner;
        profiles.setAdapter(ArrayAdapter.createFromResource(super.getActivity(), R.array.profiles_array,
                R.layout.spinner_action_row));
        profiles.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override//from   www . j  ava 2s .  com
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                final int currProfile = profilePrefs.getInt("CURR_PROFILE", 5);
                ActionBarActivity context = (ActionBarActivity) getActivity();
                switch (i) {
                case 0:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BatteryMaxProfile(), context);
                    profileCounter++;
                    break;
                case 1:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BatteryProfile(), context);
                    profileCounter++;
                    break;
                case 2:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BalancedProfile(), context);
                    profileCounter++;
                    break;
                case 3:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new PerformanceProfile(), context);
                    profileCounter++;
                    break;
                case 4:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BenchmarkProfile(), context);
                    profileCounter++;
                    break;
                }
                profilePrefs.edit().putInt("CURR_PROFILE", i).commit();
            }

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

            }
        });

        profiles.setSelection(profilePrefs.getInt("CURR_PROFILE", 5));
    }
}

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  av a 2 s.  c  o  m
    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;
}

From source file:com.eyekabob.AddBand.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addband);/*from   w w w  . j  a v  a2s . com*/
    Spinner genreSpinner = (Spinner) findViewById(R.id.genreSpinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.genres_array,
            R.layout.list_item);
    genreSpinner.setAdapter(adapter);
}

From source file:com.android.talkbacktests.testsession.StandardAndroidWidgetTest.java

@Override
public View getView(final LayoutInflater inflater, ViewGroup container, final Context context) {
    View view = inflater.inflate(R.layout.test_standard_android_widget, container, false);
    final Button contDescButton = (Button) view.findViewById(R.id.test_standard_android_widget_button2);
    contDescButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  ww . j  a  v  a  2s.c o  m*/
        public void onClick(View view) {
            mCount++;
            contDescButton.setContentDescription(getString(R.string.toast_content_changed_template, mCount));
        }
    });
    Button toastButton = (Button) view.findViewById(R.id.test_standard_android_widget_button3);
    toastButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(context, R.string.toast_expand_button_clicked, Toast.LENGTH_LONG).show();
        }
    });
    ViewCompat.setAccessibilityDelegate(toastButton, new AccessibilityDelegateCompat() {
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
                    AccessibilityNodeInfoCompat.ACTION_CLICK, getString(R.string.expand_button_action_label)));
        }
    });

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.city_array,
            android.R.layout.simple_spinner_item);

    Spinner spinner = (Spinner) view.findViewById(R.id.test_standard_android_widget_spinner);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    AutoCompleteTextView autocomplete = (AutoCompleteTextView) view
            .findViewById(R.id.test_standard_android_widget_autocomplete);
    autocomplete.setAdapter(adapter);

    mProgressBar = (ProgressBar) view.findViewById(R.id.test_standard_android_widget_progress_bar);
    mRunnable = new Runnable() {

        @Override
        public void run() {
            mProgressStatus += 5;
            mProgressBar.setProgress(mProgressStatus);
            if (mProgressStatus < 100) {
                mHandler.postDelayed(this, 1000);
            }
        }
    };
    resetProgressBar();

    View resetProgressBarButton = view.findViewById(R.id.test_standard_android_widget_reset_button);
    resetProgressBarButton.setOnClickListener(this);

    return view;
}

From source file:com.micabyte.android.app.BaseFragment.java

@SuppressWarnings("ConstantConditions")
protected Spinner setSpinner(int resId, ArrayAdapter adapter) {
    final Spinner s = (Spinner) getView().findViewById(resId);
    s.setAdapter(adapter);
    return s;/*from w w  w . j av a 2s  .com*/
}

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 www. jav  a 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:at.bitfire.davdroid.ui.CreateCalendarActivity.java

@Override
public void onLoadFinished(Loader<AccountInfo> loader, AccountInfo info) {
    Spinner spinner = (Spinner) findViewById(R.id.time_zone);
    String[] timeZones = TimeZone.getAvailableIDs();
    spinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, timeZones));
    // select system time zone
    String defaultTimeZone = TimeZone.getDefault().getID();
    for (int i = 0; i < timeZones.length; i++)
        if (timeZones[i].equals(defaultTimeZone)) {
            spinner.setSelection(i);/*from  w  w w.  ja v  a 2 s  .  c  o  m*/
            break;
        }

    if (info != null) {
        spinner = (Spinner) findViewById(R.id.home_sets);
        spinner.setAdapter(
                new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, info.homeSets));
    }
}