List of usage examples for android.widget Spinner setSelection
@Override public void setSelection(int position)
From source file:universe.constellation.orion.viewer.OrionViewerActivity.java
public void updateZoom() { SeekBar zoomSeek = (SeekBar) findMyViewById(R.id.zoom_picker_seeker); TextView textView = (TextView) findMyViewById(R.id.zoom_picker_message); Spinner sp = (Spinner) findMyViewById(R.id.zoom_spinner); int spinnerIndex = sp.getSelectedItemPosition(); zoomInternal = 1;/*from w w w .ja v a2s . c o m*/ try { int zoom = controller.getZoom10000Factor(); if (zoom <= 0) { spinnerIndex = -zoom + 1; zoom = (int) (10000 * controller.getCurrentPageZoom()); } else { spinnerIndex = 0; textView.setText("" + (zoom / 100f)); } zoomSeek.setProgress(zoom / 100); sp.setSelection(spinnerIndex); } finally { zoomInternal = 0; } }
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 ww w.ja v a 2 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:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java
void showAddNewRoutineDialog(final View entryView) { FragmentManager fm = getActivity().getSupportFragmentManager(); final RoutineCreateOrEditFragment addRoutineFragment = new RoutineCreateOrEditFragment(); addRoutineFragment.setOnRoutineEditListener(new RoutineCreateOrEditFragment.OnRoutineEditListener() { @Override/* w w w . j ava2s. c o m*/ public void onRoutineEdited(Routine r) { // do nothing } @Override public void onRoutineDeleted(Routine r) { // do nothing } @Override public void onRoutineCreated(final Routine r) { Spinner rSpinner = (Spinner) entryView.findViewById(R.id.entry_routine_spinner); String names[] = getUpdatedRoutineNames(); updateRoutineSelectionAdapter(entryView, rSpinner, names); Log.d(TAG, "Routine name: " + r.name()); Log.d(TAG, "Routine time: " + r.time().toString("hh:mm")); Log.d(TAG, "Names: " + Arrays.toString(names)); int selection = Arrays.asList(names).indexOf(r.name()); rSpinner.setSelection(selection); updateEntryTime(r, entryView); addRoutineFragment.dismiss(); } }); addRoutineFragment.show(fm, "fragment_edit_name"); }
From source file:com.xperia64.timidityae.TrackFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { reset();/*w w w .j a v a2 s . c o m*/ fileList = new ArrayAdapter<String>(getActivity(), R.layout.row); for (int i = 0; i < JNIHandler.MAX_CHANNELS; i++) { fileList.add(String.format(getActivity().getResources().getString(R.string.trk_form), (getActivity().getResources() .getString(JNIHandler.drums.get(i) ? R.string.trk_drum : R.string.trk_inst2)), (i + 1), JNIHandler.drums.get(i) ? 0 : localInst.get(i) + 1, localVol.get(i))); } channelList.setAdapter(fileList); channelList.setOnItemClickListener(new OnItemClickListener() { @SuppressLint("InflateParams") @Override public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) { AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); View v = getActivity().getLayoutInflater().inflate(R.layout.track_dialog, null); final Spinner instSpin = (Spinner) v.findViewById(R.id.instSpin); instSpin.setClickable(JNIHandler.custInst.get(arg2) && !JNIHandler.drums.get(arg2)); instSpin.setOnLongClickListener(null); instSpin.setEnabled(JNIHandler.custInst.get(arg2) && !JNIHandler.drums.get(arg2)); List<String> arrayAdapter = new ArrayList<String>(); final int offset = (!JNIHandler.drums.get(arg2)) ? 0 : 34; if (!JNIHandler.drums.get(arg2)) { for (String inst : getActivity().getResources().getStringArray(R.array.midi_instruments)) arrayAdapter.add(inst); } else { for (String inst : getActivity().getResources().getStringArray(R.array.midi_drums)) arrayAdapter.add(inst); } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, arrayAdapter); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item); } else { dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); } dataAdapter.setNotifyOnChange(false); if (!JNIHandler.drums.get(arg2)) { instSpin.setAdapter(dataAdapter); instSpin.setSelection(localInst.get(arg2) - offset); } final EditText txtVol = (EditText) v.findViewById(R.id.txtVol); txtVol.setText(Integer.toString(localVol.get(arg2))); txtVol.setClickable(JNIHandler.custVol.get(arg2)); txtVol.setEnabled(JNIHandler.custVol.get(arg2)); final SeekBar volSeek = (SeekBar) v.findViewById(R.id.volSeek); volSeek.setClickable(JNIHandler.custVol.get(arg2)); volSeek.setEnabled(JNIHandler.custVol.get(arg2)); volSeek.setMax(127); volSeek.setProgress(localVol.get(arg2)); volSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { if (arg2 && !fromUser) { fromUser = true; txtVol.setText(Integer.toString(arg0.getProgress())); } else { fromUser = false; } } @Override public void onStartTrackingTouch(SeekBar arg0) { } @Override public void onStopTrackingTouch(SeekBar arg0) { } }); txtVol.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { if (!fromUser) { if (s.length() > 0) { int numm = Integer.parseInt(s.toString()); if (numm > 127) { fromUser = true; numm = 127; } if (numm < 0) { fromUser = true; numm = 0; } if (fromUser) { txtVol.setText(Integer.toString(numm)); } fromUser = true; volSeek.setProgress(numm); fromUser = false; } } else { fromUser = false; } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); final CheckBox inst = (CheckBox) v.findViewById(R.id.defInstr); inst.setEnabled(!JNIHandler.drums.get(arg2)); inst.setChecked(!JNIHandler.custInst.get(arg2)); inst.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { instSpin.setClickable(!arg1); instSpin.setEnabled(!arg1); } }); final CheckBox vol = (CheckBox) v.findViewById(R.id.defVol); vol.setChecked(!JNIHandler.custVol.get(arg2)); //System.out.println("Def inst: "+(!JNIHandler.custInst.get(arg2)?"true":"false")+" def vol: "+(!JNIHandler.custVol.get(arg2)?"true":"false")); vol.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { volSeek.setClickable(!arg1); volSeek.setEnabled(!arg1); txtVol.setClickable(!arg1); txtVol.setEnabled(!arg1); } }); if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) v.setBackgroundColor(Globals.theme == 1 ? Color.WHITE : Color.BLACK); b.setView(v); b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JNIHandler.custInst.set(arg2, !inst.isChecked()); JNIHandler.custVol.set(arg2, !vol.isChecked()); JNIHandler.setChannelVolumeTimidity(arg2 | (JNIHandler.custVol.get(arg2) ? 0x800 : 0x8000), volSeek.getProgress()); JNIHandler.setChannelTimidity(arg2 | (JNIHandler.custInst.get(arg2) ? 0x800 : 0x8000), instSpin.getSelectedItemPosition()); if (!JNIHandler.paused && Globals.isPlaying == 0) JNIHandler.seekTo(JNIHandler.currTime); //bigCounter=12; updateList(); } }); b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); b.setTitle(String.format((getActivity().getResources().getString(R.string.trk_form2)), (arg2 + 1))); ddd = b.create(); ddd.show(); } }); }
From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceTimeProfile.java
private void restoreViewContents(final SavedViewContents sv) { final EditText dlg_prof_name_et = (EditText) mDialog.findViewById(R.id.edit_profile_time_profile_et_name); final CheckBox cb_active = (CheckBox) mDialog.findViewById(R.id.edit_profile_time_enabled); final Spinner spinnerDateTimeType = (Spinner) mDialog.findViewById(R.id.edit_profile_time_date_time_type); final Spinner spinnerYear = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_year); final Spinner spinnerMonth = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_month); final Spinner spinnerDay = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_day); final Spinner spinnerHour = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_hours); final Spinner spinnerMin = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_minutes); Handler hndl1 = new Handler(); hndl1.postDelayed(new Runnable() { @Override/*from w w w. j a va 2 s. c o m*/ public void run() { dlg_prof_name_et.setText(sv.dlg_prof_name_et); dlg_prof_name_et.setSelection(sv.dlg_prof_name_et_spos, sv.dlg_prof_name_et_epos); cb_active.setChecked(sv.cb_active); spinnerDateTimeType.setSelection(sv.spinnerDateTimeType); spinnerYear.setSelection(sv.spinnerYear); spinnerMonth.setSelection(sv.spinnerMonth); spinnerDay.setSelection(sv.spinnerDay); spinnerHour.setSelection(sv.spinnerHour); spinnerMin.setSelection(sv.spinnerMin); setDayOfTheWeekCheckBox(mGlblParms, mDialog, sv.day_of_the_week); Handler hndl2 = new Handler(); hndl2.postDelayed(new Runnable() { @Override public void run() { } }, 50); } }, 50); }
From source file:com.klokisoft.mathdokuext.ui.ArchiveFragmentActivity.java
/** * Initializes/refreshes the sizes spinner. * // ww w .j av a 2 s . c om * Returns: True in case the sizes spinner should be shown. False otherwise. */ protected void setSizeSpinner() { Spinner spinner = (Spinner) mActionBar.getCustomView().findViewById(R.id.spinner_size); if (!mShowSizeFilter || mArchiveFragmentStatePagerAdapter.getCount() == 0) { spinner.setVisibility(View.GONE); return; } // Determine which sizes are actually used for the currently // selected status filter. GridDatabaseAdapter gridDatabaseAdapter = new GridDatabaseAdapter(); final SizeFilter[] usedSizes = gridDatabaseAdapter .getUsedSizes(mArchiveFragmentStatePagerAdapter.getStatusFilter()); // Load the list of descriptions for sizes actually used into the // array adapter. String[] usedSizesDescription = new String[usedSizes.length]; for (int i = 0; i < usedSizes.length; i++) { usedSizesDescription[i] = getResources().getStringArray(R.array.archive_size_filter)[usedSizes[i] .ordinal()]; } ArrayAdapter<String> adapterStatus = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, usedSizesDescription); adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Build the spinner spinner.setAdapter(adapterStatus); // Restore selected size SizeFilter selectedSizeFilter = mArchiveFragmentStatePagerAdapter.getSizeFilter(); for (int i = 0; i < usedSizes.length; i++) { if (usedSizes[i] == selectedSizeFilter) { spinner.setSelection(i); break; } } // Hide spinner if only two choices are available. As one of those // choices is always "ALL" the choices will result in an identical // selection. spinner.setVisibility((usedSizes.length <= 2 ? View.GONE : View.VISIBLE)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Remember currently displayed grid id. int gridId = getCurrentSelectedGridId(); // Get the selected status SizeFilter sizeFilter = usedSizes[(int) id]; // Check if value for status spinner has changed. if (sizeFilter != mArchiveFragmentStatePagerAdapter.getSizeFilter()) { // Refresh pager adapter with new status. mArchiveFragmentStatePagerAdapter.setSizeFilter(sizeFilter); // Refresh the status spinner as the content of the spinners // are related. setStatusSpinner(); // If possible select the grid id which was selected before // changing the spinner(s). Otherwise select last page. selectGridId(gridId); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // Do nothing } }); }
From source file:com.example.yudiandrean.socioblood.FeedActivity.java
@SuppressLint("NewApi") @Override/*from w w w .jav a2s. c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Dialog d = new Dialog(context); setContentView(R.layout.feed_activity); postrequest = (TextView) findViewById(R.id.editText); WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE); final int width, height; ActionBar.LayoutParams params; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) { width = manager.getDefaultDisplay().getWidth(); height = manager.getDefaultDisplay().getHeight(); } else { Point point = new Point(); manager.getDefaultDisplay().getSize(point); width = point.x; height = point.y; } session = new SessionManager(getApplicationContext()); // Check if user is already logged in or not if (!session.isLoggedIn()) { // User is already logged in. Take him to main activity Intent intent = new Intent(FeedActivity.this, LoginActivity.class); startActivity(intent); finish(); } listView = (ListView) findViewById(R.id.list); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer); feedItems = new ArrayList<FeedItem>(); listAdapter = new FeedListAdapter(this, feedItems); listView.setAdapter(listAdapter); swipeRefreshLayout.setOnRefreshListener(this); // add button listener postrequest.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { try { d.requestWindowFeature(Window.FEATURE_NO_TITLE); d.setContentView(R.layout.post_request); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(d.getWindow().getAttributes()); lp.width = width; lp.height = height; d.getWindow().setAttributes(lp); } catch (AndroidRuntimeException e) { } catch (Exception e) { } final Spinner rhesusspinner = (Spinner) d.findViewById(R.id.rhesus_spinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(FeedActivity.this, android.R.layout.simple_spinner_dropdown_item) { @Override public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); if (position == getCount()) { ((TextView) v.findViewById(android.R.id.text1)).setText(""); ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed" } return v; } @Override public int getCount() { return super.getCount() - 1; // you dont display last item. It is used as hint. } }; adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.add("+"); adapter.add("-"); adapter.add("Rhesus"); rhesusspinner.setAdapter(adapter); rhesusspinner.setSelection(adapter.getCount()); //display hint final Spinner bloodspinner = (Spinner) d.findViewById(R.id.bloodtype_spinner); ArrayAdapter<String> bloodadapter = new ArrayAdapter<String>(FeedActivity.this, android.R.layout.simple_spinner_dropdown_item) { @Override public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); if (position == getCount()) { ((TextView) v.findViewById(android.R.id.text1)).setText(""); ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed" } return v; } @Override public int getCount() { return super.getCount() - 1; // you dont display last item. It is used as hint. } }; bloodadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); bloodadapter.add("O"); bloodadapter.add("A"); bloodadapter.add("B"); bloodadapter.add("AB"); bloodadapter.add("Desired Type"); bloodspinner.setAdapter(bloodadapter); bloodspinner.setSelection(bloodadapter.getCount()); //display hint //Buttons-Editexts Button btnpost = (Button) d.findViewById(R.id.post); final EditText userInput = (EditText) d.findViewById(R.id.editTextDialogUserInput); d.show(); btnpost.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (bloodspinner.getSelectedItem().toString().equals("Desired Type")) { Toast.makeText(getApplicationContext(), "Input Blood Type!", Toast.LENGTH_SHORT).show(); } else if (rhesusspinner.getSelectedItem().toString().equals("Rhesus")) { Toast.makeText(getApplicationContext(), "Input Rhesus!", Toast.LENGTH_SHORT).show(); } else if (userInput.getText().toString().equals("")) { Toast.makeText(getApplicationContext(), "Input your request message!", Toast.LENGTH_SHORT).show(); } else { int uid = session.currentUID(); String message = userInput.getText().toString(); String post_bloodtype = bloodspinner.getSelectedItem().toString(); String post_rhesus = rhesusspinner.getSelectedItem().toString(); NetAsync(d, view, uid, message, post_bloodtype, post_rhesus); } } }); } }); // // We first check for cached request // Cache cache = FeedController.getInstance().getRequestQueue().getCache(); // Entry entry = cache.get(URL_FEED); // if (entry != null) { // // fetch the data from cache // try { // String data = new String(entry.data, "UTF-8"); // try { // parseJsonFeed(new JSONObject(data)); // } catch (JSONException e) { // e.printStackTrace(); // } // } catch (UnsupportedEncodingException e) { // e.printStackTrace(); // } // // } else { // making fresh volley request and getting json /** * Showing Swipe Refresh animation on activity create * As animation won't start on onCreate, post runnable is used */ swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); getTimelineAsync(); } }); }
From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayPageFragment.java
@Override public void createAndAttachSelectQuestionDropdown(Question question, LinearLayout sectionLinearLayout) { TextView textView = new TextView(getActivity()); textView.setPadding(20, 0, 0, 0);//from w w w .j a va2 s . c o m textView.setText(question.getLabel()); Spinner spinner = (Spinner) getActivity().getLayoutInflater().inflate(R.layout.form_dropdown, null); LinearLayout questionLinearLayout = new LinearLayout(getActivity()); LinearLayout.LayoutParams questionLinearLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); questionLinearLayout.setOrientation(LinearLayout.VERTICAL); questionLinearLayoutParams.gravity = Gravity.START; questionLinearLayout.setLayoutParams(questionLinearLayoutParams); List<String> answerLabels = new ArrayList<>(); for (Answer answer : question.getQuestionOptions().getAnswers()) { answerLabels.add(answer.getLabel()); } SelectOneField spinnerField = new SelectOneField(question.getQuestionOptions().getAnswers(), question.getQuestionOptions().getConcept()); ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, answerLabels); spinner.setAdapter(arrayAdapter); LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); questionLinearLayout.addView(textView); questionLinearLayout.addView(spinner); sectionLinearLayout.setLayoutParams(linearLayoutParams); sectionLinearLayout.addView(questionLinearLayout); SelectOneField selectOneField = getSelectOneField(spinnerField.getConcept()); if (selectOneField != null) { spinner.setSelection(selectOneField.getChosenAnswerPosition()); setOnItemSelectedListener(spinner, selectOneField); } else { setOnItemSelectedListener(spinner, spinnerField); selectOneFields.add(spinnerField); } }
From source file:com.klokisoft.mathdokuext.ui.ArchiveFragmentActivity.java
/** * Initializes/refreshes the status spinner. * /*from w w w . ja v a2 s . c om*/ * Returns: True in case the status spinner should be shown. False * otherwise. */ protected void setStatusSpinner() { Spinner spinner = (Spinner) mActionBar.getCustomView().findViewById(R.id.spinner_status); if (!mShowStatusFilter || mArchiveFragmentStatePagerAdapter.getCount() == 0) { spinner.setVisibility(View.GONE); return; } // Determine which statuses are actually used for the currently // selected size filter. GridDatabaseAdapter gridDatabaseAdapter = new GridDatabaseAdapter(); final StatusFilter[] usedStatuses = gridDatabaseAdapter .getUsedStatuses(mArchiveFragmentStatePagerAdapter.getSizeFilter()); // Load the list of descriptions for statuses actually used into the // array adapter. String[] usedStatusesDescription = new String[usedStatuses.length]; for (int i = 0; i < usedStatuses.length; i++) { usedStatusesDescription[i] = getResources() .getStringArray(R.array.archive_status_filter)[usedStatuses[i].ordinal()]; } ArrayAdapter<String> adapterStatus = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, usedStatusesDescription); adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Build the spinner spinner.setAdapter(adapterStatus); // Restore selected status StatusFilter selectedStatusFilter = mArchiveFragmentStatePagerAdapter.getStatusFilter(); for (int i = 0; i < usedStatuses.length; i++) { if (usedStatuses[i] == selectedStatusFilter) { spinner.setSelection(i); break; } } // Hide spinner if only two choices are available. As one of those // choices is always "ALL" the choices will result in an identical // selection. spinner.setVisibility((usedStatuses.length <= 2 ? View.GONE : View.VISIBLE)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Get the selected status StatusFilter statusFilter = usedStatuses[(int) id]; // Check if value for status spinner has changed. if (statusFilter != mArchiveFragmentStatePagerAdapter.getStatusFilter()) { // Remember currently displayed grid id. int gridId = getCurrentSelectedGridId(); // Refresh pager adapter with new status. mArchiveFragmentStatePagerAdapter.setStatusFilter(statusFilter); // Refresh the size spinner as the content of the spinners // are related. setSizeSpinner(); // If possible select the grid id which was selected before // changing the spinner(s). Otherwise select last page. selectGridId(gridId); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // Do nothing } }); }
From source file:es.usc.citius.servando.calendula.fragments.ScheduleTimetableFragment.java
private void setupScheduleEntrySpinners(final View entryView, ScheduleItem scheduleItem, String[] routineNames) {/* ww w . j a v a2 s.co m*/ final Spinner routineSpinner = (Spinner) entryView.findViewById(R.id.entry_routine_spinner); final TextView doseTv = (TextView) entryView.findViewById(R.id.entry_dose_textview); // final Spinner doseSpinner = (Spinner) entryView.findViewById(R.id.entry_dose_spinner); doseTv.setTag(scheduleItem); routineSpinner.setTag(scheduleItem); // set up the routine selection adapter updateRoutineSelectionAdapter(entryView, routineSpinner, routineNames); if (scheduleItem != null && scheduleItem.routine() != null) { String routineName = scheduleItem.routine().name(); int index = Arrays.asList(routineNames).indexOf(routineName); routineSpinner.setSelection(index); } else { routineSpinner.setSelection(routineNames.length - 1); } doseTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showDosePickerDialog((ScheduleItem) v.getTag(), (TextView) v); } }); // set up the dose selection adapter // ArrayAdapter<String> doseAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, doses); // doseAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item); // doseSpinner.setAdapter(doseAdapter); // select 1 pill by default // doseSpinner.setSelection((int) scheduleItem.dose() - 1); // dose "1" is located at the index "0", and so on doseTv.setText(scheduleItem.displayDose()); // setup listeners routineSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { String selected = (String) adapterView.getItemAtPosition(i); Routine r = Routine.findByName(selected); ScheduleItem item = ((ScheduleItem) routineSpinner.getTag()); if (r != null) { updateEntryTime(r, entryView); } else { updateEntryTime(null, entryView); showAddNewRoutineDialog(entryView); } Log.d(TAG, "Updated routine to " + (r != null ? r.name() : "NULL") + " on item " + item.getId()); item.setRoutine(r); logScheduleItems(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); routineSpinner.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_UP) { if (((String) routineSpinner.getSelectedItem()) .equalsIgnoreCase(getString(R.string.create_new_routine))) { showAddNewRoutineDialog(entryView); return true; } } return false; } }); }