List of usage examples for android.widget ArrayAdapter setDropDownViewResource
public void setDropDownViewResource(@LayoutRes int resource)
Sets the layout resource to create the drop down views.
From source file:com.markupartist.sthlmtraveling.ChangeRouteTimeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.change_route_time); registerScreen("Change route time"); restoreState(savedInstanceState);//from w ww . j ava 2 s. c o m Bundle extras = getIntent().getExtras(); mJourneyQuery = extras.getParcelable(RoutesActivity.EXTRA_JOURNEY_QUERY); mTime = mJourneyQuery.time; mDateButton = (Button) findViewById(R.id.change_route_date); mDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDialog(DIALOG_DATE); } }); mTimeButton = (Button) findViewById(R.id.change_route_time); mTimeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDialog(DIALOG_TIME); } }); ImageButton refreshTimeButton = (ImageButton) findViewById(R.id.btn_set_to_now); ViewHelper.tintIcon(refreshTimeButton.getDrawable(), Color.GRAY); refreshTimeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mJourneyQuery.time != null) { mJourneyQuery.time.setTime(System.currentTimeMillis()); updateTimeViews(); } } }); // Don't fill via if it has been restored. if (!mViaPoint.looksValid() && mJourneyQuery.hasVia()) { mViaPoint = mJourneyQuery.via; // new Site(); // mViaPoint.setId(mJourneyQuery.via.id); // mViaPoint.setName(mJourneyQuery.via.name); // mViaPoint.setLocation(mJourneyQuery.via.latitude, mJourneyQuery.via.longitude); } mViaPointAutoComplete = createAutoCompleteTextView(R.id.via, mViaPoint, true); mViaPointAutoComplete.setText(mViaPoint.getName()); int selectedPosition = mJourneyQuery.isTimeDeparture ? 0 : 1; mWhenSpinner = (Spinner) findViewById(R.id.departure_arrival_choice); ArrayAdapter<CharSequence> whenChoiceAdapter = ArrayAdapter.createFromResource(this, R.array.when_choice, android.R.layout.simple_spinner_item); whenChoiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mWhenSpinner.setAdapter(whenChoiceAdapter); mWhenSpinner.setSelection(selectedPosition); // Inflate a "Done/Discard" custom action bar view. LayoutInflater inflater = (LayoutInflater) getSupportActionBar().getThemedContext() .getSystemService(LAYOUT_INFLATER_SERVICE); final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done_discard, null); customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(this); customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(this); // Show the custom action bar view and hide the normal Home icon and title. final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); updateViews(); }
From source file:com.farbod.labelledspinner.LabelledSpinner.java
/** * Sets the array of items to be used in the Spinner. * * @param itemsArray The array used as the data source * @param spinnerItemRes The identifier of the layout used to create * views (e.g. {@code R.layout.my_item}) * @param dropdownViewRes The layout resource to create the drop down * views (e.g. {@code R.layout.my_dropdown}) * * @see #setItemsArray(int)// w ww . j a v a 2 s.c o m * @see #setItemsArray(int, int, int) * @see #setItemsArray(CharSequence[]) * @see #setItemsArray(List) * @see #setItemsArray(List, int, int) * * @attr ref R.styleable#LabelledSpinner_entries */ public void setItemsArray(CharSequence[] itemsArray, @LayoutRes int spinnerItemRes, @LayoutRes int dropdownViewRes) { ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(), spinnerItemRes, itemsArray); adapter.setDropDownViewResource(dropdownViewRes); mSpinner.setAdapter(adapter); }
From source file:com.ubundude.timesheet.ReportFragment.java
@Override public void onStart() { super.onStart(); /** Get the shared preference for the first day of the week */ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); firstDay = prefs.getString(getActivity().getString(R.string.prefDOWKey), "SUNDAY"); firstDOW = getFirstDay(firstDay);/*from w w w .j ava 2 s . c om*/ hoursTextView = (TextView) getView().findViewById(R.id.rHoursTV); rSpinner = (Spinner) getView().findViewById(R.id.rSpinner); ArrayAdapter<CharSequence> adapt = ArrayAdapter.createFromResource(getActivity(), R.array.reports, android.R.layout.simple_spinner_item); adapt.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); rSpinner.setAdapter(adapt); rSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { switch (pos) { case 0: sendDate = formDate.format(c.getTime()); dateView = formDay.format(c.getTime()) + "\n" + formDate.format(c.getTime()); dateEditText.setText(dateView); reportType = 0; getTimestamps(sendDate, reportType); break; case 1: dateView = formWIY.format(c.getTime()); sendDate = dateView; dateEditText.setText(dateView); reportType = 1; getTimestamps(sendDate, reportType); break; case 2: sendDate = formMonthNum.format(c.getTime()); monthHelp = Integer.parseInt(sendDate) - 1; sendDate = Integer.toString(monthHelp); Log.d("Spinner Switch", "Date is: " + sendDate); dateView = formMonth.format(c.getTime()); Log.d("Spinner Switch", "DateView is: " + dateView); dateEditText.setText(dateView); reportType = 2; getTimestamps(sendDate, reportType); break; } } public void onNothingSelected(AdapterView<?> parent) { } }); dateView = formDay.format(c.getTime()) + "\n" + formDate.format(c.getTime()); sendDate = formDate.format(c.getTime()); gDate = sendDate; getTimestamps(sendDate, reportType); /** Instantiates the dateEditText, set's it's text to the dateView, and sets the onClickListener */ dateEditText = (EditText) getView().findViewById(R.id.rDateEditText); dateEditText.setText(dateView); dateEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /** Gets the date based on the report type selected */ switch (reportType) { case 0: Log.d("Initial Dates", "In the On Click Listener"); arrDate = gDate.split("/"); year = Integer.valueOf(arrDate[2]); month = Integer.valueOf(arrDate[0]) - 1; dayOfMonth = Integer.valueOf(arrDate[1]); new DatePickerDialog(getActivity(), d, year, month, dayOfMonth).show(); break; case 1: sendDate = dateEditText.getText().toString(); arrDate = gDate.split("/"); year = Integer.valueOf(arrDate[2]); month = Integer.valueOf(arrDate[0]) - 1; dayOfMonth = Integer.valueOf(arrDate[1]); new DatePickerDialog(getActivity(), d, year, month, dayOfMonth).show(); break; case 2: pickMonth(); break; } } }); /** * Initialize minus button * * This method calls the minus button handler and stores the date returned * and also gets new timestamps for the date returned. */ minusButton = (Button) getView().findViewById(R.id.rMinusButton); minusButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { sendDate = minusButtonHandler(); getTimestamps(sendDate, reportType); } catch (ParseException e) { e.printStackTrace(); } } }); /** * Initialize plus button * * This method calls the plus button handler and stores the date returned * and also gets new timestamps for the date returned. */ plusButton = (Button) getView().findViewById(R.id.rPlusButton); plusButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { sendDate = plusButtonHandler(); getTimestamps(sendDate, reportType); } catch (ParseException e) { e.printStackTrace(); } } }); }
From source file:com.mifos.mifosxdroid.online.CreateNewClientFragment.java
private void inflateClientTypeOptions() { final ArrayList<String> ClientTypeNames = filterListObject(clientstemplate.getClientTypeOptions()); final ArrayAdapter<String> clientTypeAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, ClientTypeNames); clientTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spClientType.setAdapter(clientTypeAdapter); spClientType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//from w w w . j av a 2 s .com public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { clientTypeId = clientstemplate.getClientTypeOptions().get(i).getId(); Log.d("clientTypeId " + ClientTypeNames.get(i), String.valueOf(clientTypeId)); if (clientTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_office), Toast.LENGTH_SHORT) .show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.parking.billing.ParkingPayment.java
/** * Sets up the UI.//w ww .j a v a 2 s . c o m */ private void setupWidgets() { mBuyButton = (Button) findViewById(R.id.buy_button); mBuyButton.setEnabled(false); mBuyButton.setOnClickListener(this); mSelectLicensePlateSpinner = (Spinner) findViewById(R.id.license_plate_choices); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, AppPreferences.getInstance().getLicensePlateList()); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSelectLicensePlateSpinner.setAdapter(spinnerArrayAdapter); //mSelectItemSpinner = (Spinner) findViewById(R.id.item_choices); mCatalogAdapter = new CatalogAdapter(this, CATALOG); //mSelectItemSpinner.setAdapter(mCatalogAdapter); paymentCalculation(); //mSelectItemSpinner.setOnItemSelectedListener(this); }
From source file:com.mifos.mifosxdroid.online.CreateNewClientFragment.java
public void inflateStaffSpinner(final int officeId) { App.apiManager.getStaffInOffice(officeId, new Callback<List<Staff>>() { @Override/*from w w w. j a v a 2 s. c o m*/ public void success(List<Staff> staffs, Response response) { final List<String> staffNames = new ArrayList<String>(); for (Staff staff : staffs) { staffNames.add(staff.getDisplayName()); staffNameIdHashMap.put(staff.getDisplayName(), staff.getId()); } ArrayAdapter<String> staffAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, staffNames); staffAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_staff.setAdapter(staffAdapter); sp_staff.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { staffId = staffNameIdHashMap.get(staffNames.get(position)); Log.d("staffId " + staffNames.get(position), String.valueOf(staffId)); if (staffId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_staff), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); } @Override public void failure(RetrofitError error) { Log.d(LOG_TAG, error.getLocalizedMessage()); } }); }
From source file:com.mifos.mifosxdroid.online.CreateNewClientFragment.java
private void inflateClientClassificationOptions() { final ArrayList<String> ClientClassificationNames = filterListObject( clientstemplate.getClientClassificationOptions()); ArrayAdapter<String> ClientClassificationAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, ClientClassificationNames); ClientClassificationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spClientClassification.setAdapter(ClientClassificationAdapter); spClientClassification.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//ww w.j a va2 s .c om public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { clientClassificationId = clientstemplate.getClientClassificationOptions().get(i).getId(); Log.d("clientClassificationId" + ClientClassificationNames.get(i), String.valueOf(clientClassificationId)); if (clientClassificationId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_client_type), Toast.LENGTH_SHORT) .show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:felixwiemuth.lincal.ui.CalendarViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.calendar_view, container, false); TextView titleView = (TextView) rootView.findViewById(R.id.cal_title); TextView authorView = (TextView) rootView.findViewById(R.id.cal_author); notificationsEnabled = (CheckBox) rootView.findViewById(R.id.notifications_enabled); textViewEarliestNotificationTime = (TextView) rootView .findViewById(R.id.setting_earliest_notification_time); earliestNotificationTimeEnabled = (CheckBox) rootView .findViewById(R.id.setting_earliest_notification_time_enabled); entryDisplayModeDate = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_date); entryDisplayModeDescription = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_description); buttonRemoveCalendar = (Button) rootView.findViewById(R.id.button_remove_cal); if (calendar == null) { titleView.setText(R.string.cal_title_error_loading); notificationsEnabled.setEnabled(false); earliestNotificationTimeEnabled.setEnabled(false); entryDisplayModeDate.setEnabled(false); entryDisplayModeDescription.setEnabled(false); } else {/* w ww .j ava 2 s. com*/ titleView.setText(calendar.getTitle()); authorView.setText(calendar.getAuthor()); entryList = (RecyclerView) rootView.findViewById(R.id.entry_list_recycler_view); SimpleItemRecyclerViewAdapter adapter = new SimpleItemRecyclerViewAdapter(); entryList.setAdapter(adapter); ((TextView) rootView.findViewById(R.id.cal_descr)).setText(calendar.getDescription()); ((TextView) rootView.findViewById(R.id.cal_version)).setText(calendar.getVersion()); ((TextView) rootView.findViewById(R.id.cal_date)).setText(calendar.getDateStr()); if (calendar.hasForceEntryDisplayModeDate()) { entryDisplayModeDate.setEnabled(false); } if (calendar.hasForceEntryDisplayModeDescription()) { entryDisplayModeDescription.setEnabled(false); } } ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getContext(), R.array.setting_entry_display_mode_options, android.R.layout.simple_spinner_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); entryDisplayModeDate.setAdapter(spinnerAdapter); entryDisplayModeDescription.setAdapter(spinnerAdapter); loadSettings(); // loading settings before adding listeners prevents them from firing due to initialization (e.g. Spinner) if (calendar != null) { // Set listeners final View.OnClickListener saveSettingsListener = new View.OnClickListener() { @Override public void onClick(View v) { saveSettings(); NotificationService.runWithCalendar(getContext(), Calendars.getInstance(getContext()).getConfigByPos(calendarPos).getId()); //TODO reconsider when to call } }; notificationsEnabled.setOnClickListener(saveSettingsListener); textViewEarliestNotificationTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadSettings(); // update earliestNotificationTime DialogFragment dialogFragment = new TimePickerFragment(); Bundle arguments = new Bundle(); arguments.putInt("hour", earliestNotificationTime.getHour()); arguments.putInt("minute", earliestNotificationTime.getMinute()); arguments.putInt("calendarPos", calendarPos); dialogFragment.setArguments(arguments); dialogFragment.show(getFragmentManager(), "timePicker"); } }); earliestNotificationTimeEnabled.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveSettingsListener.onClick(v); // have to update the displayed notification times (only show when enabled) entryList.getAdapter().notifyDataSetChanged(); } }); //TODO implement // onScreenOnEnabled = (CheckBox) rootView.findViewById(R.id.setting_show_notification_on_screen_on); // onScreenOnEnabled.setOnClickListener(saveSettingsListener); entryDisplayModeDate.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener( entryDisplayModeDate.getSelectedItemPosition(), saveSettingsListener)); entryDisplayModeDescription.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener( entryDisplayModeDescription.getSelectedItemPosition(), saveSettingsListener)); } buttonRemoveCalendar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(R.string.dialog_remove_cal_title).setMessage(R.string.dialog_remove_cal_msg) .setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // First remove this fragment, so that it cannot be used anymore getActivity().getSupportFragmentManager().beginTransaction() .remove(CalendarViewFragment.this).commit(); Calendars calendars = Calendars.getInstance(getContext()); calendars.removeCalendarByPos(getContext(), calendarPos); // Notify calendar list that the calendar with the given position was removed and return to calendar list in case of CalendarViewActivity Activity hostActivity = getActivity(); if (hostActivity instanceof CalendarListActivity) { ((CalendarListActivity) hostActivity).notifyCalendarRemoved(calendarPos); } else if (hostActivity instanceof CalendarViewActivity) { Intent resultData = new Intent(); resultData.putExtra(CalendarListActivity.EXTRA_RESULT_CAL_REMOVED, calendarPos); hostActivity.setResult(Activity.RESULT_OK, resultData); hostActivity.finish(); } else { throw new RuntimeException( "CalendarViewFragment may only be contained in either CalendarListActivity or CalendarViewActivity."); } } }); builder.show(); } }); return rootView; }
From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main);//from w w w.ja va 2 s . c om SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_view); surfaceView.setOnTouchListener(this); surfaceHolder = surfaceView.getHolder(); surfaceHolder.setFormat(PixelFormat.RGB_565); surfaceHolder.addCallback(this); messageView = (TextView) findViewById(R.id.message_label); messageView.bringToFront(); transparentView = findViewById(R.id.transparent_view); numPlayersSelector = (Spinner) findViewById(R.id.num_players); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.playerNumber, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); numPlayersSelector.setAdapter(adapter); button = (Button) findViewById(R.id.continue_button); button.setOnClickListener(this); statusTopleft = (TextView) findViewById(R.id.status_topleft); statusTopright = (TextView) findViewById(R.id.status_topright); statusBotleft = (TextView) findViewById(R.id.status_botleft); statusBotright = (TextView) findViewById(R.id.status_botright); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); onClick(drawerView); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (activityState == ActivityStateEnum.GAMERUNNING) showPauseScreen(); } }); statusTopright.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { statusTopright.setTextColor(0xffCCCCFF); secretHandshake += 1; } }); statusBotright.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (secretHandshake > 4) { statusBotright.setTextColor(0xffCCCCFF); final NetworkIP n = new NetworkIP((int) System.currentTimeMillis()); n.startServer(); n.clientConnect("127.0.0.1", 1234); } } }); scores = new Scores(getSharedPreferences("scores", Context.MODE_PRIVATE)); scores.loadScores(); if (savedInstanceState == null) { showIntroScreen(); } }
From source file:com.farbod.labelledspinner.LabelledSpinner.java
/** * Sets the array of items to be used in the Spinner. * * @param arrayResId The identifier of the array to use as the data * source (e.g. {@code R.array.myArray}) * @param spinnerItemRes The identifier of the layout used to create * views (e.g. {@code R.layout.my_item}) * @param dropdownViewRes The layout resource to create the drop down * views (e.g. {@code R.layout.my_dropdown}) * * @see #setItemsArray(int)/* w w w. j a v a2s . co m*/ * @see #setItemsArray(CharSequence[]) * @see #setItemsArray(CharSequence[], int, int) * @see #setItemsArray(List) * @see #setItemsArray(List, int, int) * * @attr ref R.styleable#LabelledSpinner_entries */ public void setItemsArray(@ArrayRes int arrayResId, @LayoutRes int spinnerItemRes, @LayoutRes int dropdownViewRes) { ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), arrayResId, spinnerItemRes); adapter.setDropDownViewResource(dropdownViewRes); mSpinner.setAdapter(adapter); }