List of usage examples for android.widget Spinner setAdapter
@Override public void setAdapter(SpinnerAdapter adapter)
From source file:com.microsoft.aad.adal.example.userappwithbroker.AcquireTokenFragment.java
void bindSpinnerChoice(final Spinner spinner, final Class<? extends Enum> spinnerChoiceClass) { final ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, new ArrayList<String>() { {/*ww w. j a va 2 s .c o m*/ for (Enum choice : spinnerChoiceClass.getEnumConstants()) add(choice.name()); } }); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); }
From source file:com.example.android.gcncouponalert.app.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); //Spinner spinner = (Spinner) findViewById(R.id.coupons_spinner); MenuItem item = menu.findItem(R.id.coupons_spinner); Spinner spinner = (Spinner) item.getActionView(); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.coupon_filter_options, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*ww w.ja v a2 s .c om*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Log.d(LOG_TAG, " onItemSelected: " + position + "; " + id); CouponsFragment ff = (CouponsFragment) getSupportFragmentManager() .findFragmentById(R.id.fragment_forecast); if (null != ff) { ff.onSpinnerChanged(position); } } @Override public void onNothingSelected(AdapterView<?> parent) { // sometimes you need nothing here } }); //MenuItem item = menu.findItem(R.id.coupons_spinner); //Spinner spinner =(Spinner) item.getActionView(); //setupSpinner(spinner); //String[] items={"All","Favorites"}; //wrap the items in the Adapter //ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items); //assign adapter to the Spinner //spinner.setAdapter(adapter); //MenuItem item = menu.findItem(R.id.coupons_spinner); //Spinner spinner = (Spinner) MenuItemCompat.getActionView(item); //spinner.setAdapter(adapter); // set the adapter to provide layout of rows and content //s.setOnItemSelectedListener(onItemSelectedListener); // set the listener, to perform actions based on item selection return true; }
From source file:com.example.pyrkesa.frag.User_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true);/*from w w w. java 2 s .c o m*/ rootView = inflater.inflate(R.layout.user_fragment, container, false); userList = (ListView) rootView.findViewById(R.id.lt_user); // custom dialog final Dialog dialog = new Dialog(rootView.getContext()); d = dialog; userIcons = getResources().obtainTypedArray(R.array.userIcons);// load icons from userIcons1 = getResources().obtainTypedArray(R.array.userIcons1); userItems = new ArrayList<UserItem>(); adapter = new UserAdapter(getActivity(), userItems, getActivity()); userList.setAdapter(adapter); ImageButton addButton = (ImageButton) rootView.findViewById(R.id.add); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ModelFactory model = (ModelFactory) ModelFactory.getContext(); if (model.user.type == 1) { dialog.setContentView(R.layout.adduser_dialog); dialog.setTitle("Ajouter un utilisateur "); dialogTypes = getResources().getStringArray(R.array.user_type_dialog); // load Button dialogButtonOk = (Button) dialog.findViewById(R.id.button_ok); Button dialogButtonCancel = (Button) dialog.findViewById(R.id.button_cancel); final EditText Newlogin = (EditText) dialog.findViewById(R.id.dialogLogin); final EditText NewPW = (EditText) dialog.findViewById(R.id.dialogPW); final Spinner NewType = (Spinner) dialog.findViewById(R.id.dialogType); ArrayList<String> types = new ArrayList<String>(); for (String t : dialogTypes) { types.add(t); } NewType.setAdapter(new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_dropdown_item, types)); dialogButtonCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialogButtonOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ArrayList<String> temp = new ArrayList<String>(); String login = Newlogin.getText().toString(); String password = NewPW.getText().toString(); String type = NewType.getSelectedItem().toString(); if (login.equalsIgnoreCase("") && password.equalsIgnoreCase("") && type != null) { new AlertDialog.Builder(v.getContext()).setTitle("Attention") .setMessage("Veuillez remplir toutes les informations.").show(); } else { temp.add(login); temp.add(password); if (type.equalsIgnoreCase("admin")) { temp.add("1"); } else if (type.equalsIgnoreCase("utilisateur")) { temp.add("0"); } else { temp.add("0"); } } new addUser().execute(temp); } }); dialog.show(); } else { new AlertDialog.Builder(v.getContext()).setTitle("Attention") .setMessage("Opration interdite : Droits d'administration requis.").show(); } } }); // adding user items new LoadAllUser().execute(); return rootView; }
From source file:li.klass.fhem.fragments.TimerDetailFragment.java
private void createTargetStateSpinner(View view) { Spinner targetState = getTargetStateSpinner(view); targetStateAdapter = new ArrayAdapter<>(getActivity(), R.layout.spinnercontent); targetState.setAdapter(targetStateAdapter); view.findViewById(R.id.targetStateRow).setVisibility(View.GONE); targetState.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//from w ww .j a va 2 s .c o m public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (targetDevice == null) { Log.e(TAG, "cannot select new target state, as new target device is set!"); return; } else if (targetDevice.getSetList().size() == 0) { Log.e(TAG, "cannot select new target state, as the new device does not contain any target states!"); return; } String newTargetState = targetDevice.getSetList().getSortedKeys().get(i); if (TimerDetailFragment.this.targetState == null || !TimerDetailFragment.this.targetState.equals(newTargetState)) { selectTargetState(newTargetState); setTargetStateAppendix(null); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); }
From source file:eu.trentorise.smartcampus.communicator.fragments.messages.AbstractMessageListFragment.java
@SuppressWarnings("unchecked") protected void setupSelectors() { if (hasLabelSelector()) { if (isLabelSelectorEnabled()) { ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner labelFilter = (Spinner) getView().findViewById(R.id.messages_spinner_labels); labelFilter.setAdapter(dataAdapter); for (String n : CommunicatorHelper.getLabelsForSelector()) { ((ArrayAdapter<String>) labelFilter.getAdapter()).add(n); }/*from www.j a va2 s . co m*/ labelFilter.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0 && filter.getLabelId() == null) return; LabelObject selected = null; try { String selectedString = (String) labelFilter.getAdapter().getItem(position); selected = CommunicatorHelper.getLabelByName(selectedString); if (selected != null) { if (selected.getId().equals(filter.getLabelId())) return; filter.setLabelId(selected.getId()); } else filter.setLabelId(null); } catch (Exception e) { labelFilter.setSelection(0); } updateMessageList(); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); } else { getView().findViewById(R.id.messages_spinner_labels).setEnabled(false); } } else { ((LinearLayout) getView().findViewById(R.id.messages_filters)) .removeView(getView().findViewById(R.id.messages_spinner_labels)); } }
From source file:com.kunze.androidlocaltodo.TaskActivityFragment.java
private void InitializeView(final View rootView) { final View activityView = rootView; TextWatcher textWatcher = new TextWatcher() { @Override/*from w ww . java 2s . c o m*/ public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { TaskChanged(activityView); } }; final EditText nameEdit = (EditText) rootView.findViewById(R.id.task_name_edit); final TextView nameStatic = (TextView) rootView.findViewById(R.id.task_name_static); nameStatic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { nameEdit.setVisibility(View.VISIBLE); nameStatic.setVisibility(View.INVISIBLE); } }); nameEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { nameEdit.setVisibility(View.INVISIBLE); nameStatic.setVisibility(View.VISIBLE); } } }); nameEdit.addTextChangedListener(textWatcher); final TextView descriptionEdit = (TextView) rootView.findViewById(R.id.task_description_edit); descriptionEdit.addTextChangedListener(textWatcher); final TextView dueDateView = (TextView) rootView.findViewById(R.id.due_date_text); final DatePicker datePicker = (DatePicker) rootView.findViewById(R.id.due_date_calendar); datePicker.init(0, 0, 0, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(year, monthOfYear, dayOfMonth, 0, 0, 0); SetFriendlyDueDateText(dueDateView, calendar); TaskChanged(activityView); } }); Button todayButton = (Button) rootView.findViewById(R.id.today_button); todayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar now = Calendar.getInstance(); datePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, now); } }); Button plusDayButton = (Button) rootView.findViewById(R.id.plus_day_button); plusDayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); calendar.add(Calendar.DATE, 1); datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, calendar); } }); Button thisWeekendButton = (Button) rootView.findViewById(R.id.this_weekend_button); thisWeekendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar weekend = Calendar.getInstance(); while (weekend.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { weekend.add(Calendar.DATE, 1); } datePicker.updateDate(weekend.get(Calendar.YEAR), weekend.get(Calendar.MONTH), weekend.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, weekend); } }); Button plusWeekButton = (Button) rootView.findViewById(R.id.plus_week_button); plusWeekButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); calendar.add(Calendar.DATE, 7); datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, calendar); } }); final CheckBox repeatCheck = (CheckBox) rootView.findViewById(R.id.repeat); repeatCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { View dialog = (View) buttonView.getParent(); SetRepeatVisibility(dialog, isChecked); TaskChanged(activityView); } }); final EditText repeatTimeEdit = (EditText) rootView.findViewById(R.id.repeat_time); repeatTimeEdit.addTextChangedListener(textWatcher); final Spinner repeatUnitSpinner = (Spinner) rootView.findViewById(R.id.repeat_unit); String[] repeatUnits = { "Days", "Weeks", "Months", "Years" }; repeatUnitSpinner.setAdapter( new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, repeatUnits)); repeatUnitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (mRow != -1 && mRow != id) { TaskChanged(activityView); } mRow = id; } @Override public void onNothingSelected(AdapterView<?> arg0) { TaskChanged(activityView); } private long mRow = -1; }); final RadioButton repeatFromComplete = (RadioButton) rootView.findViewById(R.id.repeat_from_complete); final RadioButton repeatFromDue = (RadioButton) rootView.findViewById(R.id.repeat_from_due); Button revertButton = (Button) rootView.findViewById(R.id.revert_button); Button acceptButton = (Button) rootView.findViewById(R.id.accept_button); final Button doneButton = (Button) rootView.findViewById(R.id.done_button); Button deleteButton = (Button) rootView.findViewById(R.id.delete_button); revertButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mNewTask = new Task(mOriginalTask); mProgrammaticChange = true; InitializeViewFields(activityView, mOriginalTask); mProgrammaticChange = false; TaskReverted(activityView); } }); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(doneButton.getContext()); builder.setTitle("Done?"); builder.setMessage("Mark task \"" + mNewTask.mName + "\" as done?"); builder.setNegativeButton("No", null); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mNewTask.Done(); TaskDatabase db = new TaskDatabase(getActivity()); db.SaveTask(mNewTask); InitializeViewFields(rootView, mNewTask); } }); builder.show(); } }); }
From source file:com.mbientlab.metawear.app.LoggingFragment.java
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { Spinner spinnerObj; spinnerObj = (Spinner) view.findViewById(R.id.spinner1); spinnerObj.setAdapter( new ArrayAdapter<Sensor>(getActivity(), R.layout.command_row, R.id.command_name, sensors)); spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() { @Override//from w ww.j a v a 2 s. c o m public void onItemSelected(AdapterView<?> parent, View innerView, int position, long id) { sensorIndex = position; TextView description = (TextView) view.findViewById(R.id.textView2); description.setText(sensors[sensorIndex].getDescription()); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ((Button) view.findViewById(R.id.button1)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mwMnger.controllerReady()) { mwMnger.getCurrentController().addModuleCallback(sensors[sensorIndex]); sensors[sensorIndex].setupLogger(); } else { Toast.makeText(getActivity(), R.string.error_connect_board, Toast.LENGTH_LONG).show(); } } }); ((Button) view.findViewById(R.id.button2)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mwMnger.controllerReady()) { mwMnger.getCurrentController().addModuleCallback(sensors[sensorIndex]); sensors[sensorIndex].stopSensors(); if (sensors[sensorIndex].dataReady()) { startEmailIntent(); } else { loggingController.stopLogging(); loggingController.readTotalEntryCount(); } } else { Toast.makeText(getActivity(), R.string.error_connect_board, Toast.LENGTH_LONG).show(); } } }); }
From source file:me.fattycat.kun.teamwork.ui.activity.MainActivity.java
private void initView() { mFab.setOnClickListener(new View.OnClickListener() { @Override//from w w w . ja va2 s . c o m public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null) .show(); } }); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); mDrawerLayout.addDrawerListener(toggle); toggle.syncState(); mNavView.setNavigationItemSelectedListener(this); View navHeadView = mNavView.getHeaderView(0); mProfileImage = (CircleImageView) navHeadView.findViewById(R.id.profile_image); mTvProfileName = (TextView) navHeadView.findViewById(R.id.profile_name); mTvProfileDesc = (TextView) navHeadView.findViewById(R.id.profile_description); Spinner spinnerProfileTeam = (Spinner) navHeadView.findViewById(R.id.profile_team_spinner); mUserTeamAdapter = new ArrayAdapter<>(mContext, R.layout.spinner_item_team); mUserTeamAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerProfileTeam.setAdapter(mUserTeamAdapter); spinnerProfileTeam.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { TWSettings.sSelectedTeamPos = position; getTeamProjects(mUserTeamList.get(position).getTeam_id()); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); // FIXME: 16/3/24 temporary refresh mProfileImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getUserProfile(); } }); mTabLayout.setVisibility(View.GONE); }
From source file:com.odoo.OdooActivity.java
public Spinner getActionBarSpinner() { Spinner spinner = null; if (mHasActionBarSpinner) { spinner = (Spinner) findViewById(R.id.spinner_nav); spinner.setAdapter(null); }//from w w w .j a v a2 s .c om return spinner; }
From source file:cz.zcu.kiv.eeg.mobile.base.ui.scenario.ScenarioAddActivity.java
/** * Method for initializing layout elements. * Sets limit for description text length and an adapter for research group list. *//*from ww w .j a va 2 s. co m*/ private void initView() { //obtaining view elements final TextView descriptionCountText = (TextView) findViewById(R.id.scenario_description_count); EditText descriptionText = (EditText) findViewById(R.id.scenario_description_value); Spinner groupList = (Spinner) findViewById(R.id.groupList); //limiting description text length descriptionText.addTextChangedListener(new LimitedTextWatcher( getResources().getInteger(R.integer.limit_description_chars), descriptionCountText)); //setting adapter for list of research groups researchGroupAdapter = new ResearchGroupAdapter(this, R.layout.base_row_simple, new ArrayList<ResearchGroup>()); groupList.setAdapter(researchGroupAdapter); }