List of usage examples for android.widget ArrayAdapter createFromResource
public static @NonNull ArrayAdapter<CharSequence> createFromResource(@NonNull Context context, @ArrayRes int textArrayResId, @LayoutRes int textViewResId)
From source file:eu.power_switch.gui.fragment.alarm_clock.StockAlarmClockFragment.java
@Override public void onCreateViewEvent(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_stock_alarm_clock, container, false); setHasOptionsMenu(true);/*from w w w. jav a 2 s . c o m*/ final RecyclerViewFragment recyclerViewFragment = this; Switch switchOnOff = (Switch) rootView.findViewById(R.id.switch_on_off); switchOnOff.setChecked(SmartphonePreferencesHandler.getStockAlarmClockEnabled()); switchOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.isPressed()) { SmartphonePreferencesHandler.setStockAlarmClockEnabled(isChecked); } } }); spinnerEventType = (Spinner) rootView.findViewById(R.id.spinner_sleep_as_android_event); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.stock_alarm_clock_event_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerEventType.setAdapter(adapter); SpinnerInteractionListener spinnerInteractionListener = new SpinnerInteractionListener() { @Override public void onItemSelectedByUser(AdapterView<?> parent, View view, int pos, long id) { updateUI(); } }; spinnerEventType.setOnItemSelectedListener(spinnerInteractionListener); spinnerEventType.setOnTouchListener(spinnerInteractionListener); recyclerViewActions = (RecyclerView) rootView.findViewById(R.id.recyclerView); recyclerViewAdapter = new ActionRecyclerViewAdapter(getContext(), actions); recyclerViewAdapter.setOnDeleteClickListener(new ActionRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, final int position) { new AlertDialog.Builder(getContext()).setTitle(R.string.delete).setMessage(R.string.are_you_sure) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { actions.remove(position); DatabaseHandler.setAlarmActions( Event.getById(spinnerEventType.getSelectedItemPosition()), actions); StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(), R.string.action_removed, Snackbar.LENGTH_LONG); } catch (Exception e) { StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e); } recyclerViewAdapter.notifyDataSetChanged(); } }).setNeutralButton(android.R.string.cancel, null).show(); } }); recyclerViewActions.setAdapter(recyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); recyclerViewActions.setLayoutManager(layoutManager); addActionFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab); addActionFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); addActionFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddStockAlarmClockEventActionDialog addAlarmEventActionDialog = AddStockAlarmClockEventActionDialog .newInstance(spinnerEventType.getSelectedItemPosition()); addAlarmEventActionDialog.setTargetFragment(recyclerViewFragment, 0); addAlarmEventActionDialog.show(getActivity().getSupportFragmentManager(), null); } }); // BroadcastReceiver to get notifications from background service if room data has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(this, "received intent: " + intent.getAction()); if (LocalBroadcastConstants.INTENT_ALARM_EVENT_ACTION_ADDED.equals(intent.getAction())) { updateUI(); } else { updateUI(); } } }; }
From source file:org.gateshipone.malp.application.fragments.serverfragments.SearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_server_search, container, false); // Get the main ListView of this fragment mListView = (ListView) rootView.findViewById(R.id.main_listview); // Create the needed adapter for the ListView mFileAdapter = new FileAdapter(getActivity(), false, true); // Combine the two to a happy couple mListView.setAdapter(mFileAdapter);//from ww w . java 2 s . c o m mListView.setOnItemClickListener(this); registerForContextMenu(mListView); mSelectSpinner = (Spinner) rootView.findViewById(R.id.search_criteria); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.server_search_choices, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mSelectSpinner.setAdapter(adapter); mSelectSpinner.setOnItemSelectedListener(new SpinnerSelectListener()); mSearchView = (SearchView) rootView.findViewById(R.id.search_text); mSearchView.setOnQueryTextListener(new SearchViewQueryListener()); mSearchView.setOnFocusChangeListener(this); // get swipe layout mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_layout); // set swipe colors mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getThemeColor(getContext(), R.attr.colorAccent), ThemeUtils.getThemeColor(getContext(), R.attr.colorPrimary)); // set swipe refresh listener mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshContent(); } }); setHasOptionsMenu(true); // Return the ready inflated and configured fragment view. return rootView; }
From source file:com.anton.gavel.GavelMain.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_gavel_main); // set up edit text input style for complaints (multiline, capitalize sentences) EditText edit = (EditText) findViewById(R.id.complaint_body); edit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE); // set up cities spinner Spinner citiesSpinner = (Spinner) findViewById(R.id.cities_spinner); ArrayAdapter<CharSequence> citiesAdapter = ArrayAdapter.createFromResource(this, R.array.cities, android.R.layout.simple_spinner_item); citiesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); citiesSpinner.setAdapter(citiesAdapter); // set up complaints map List<String> standardComplaints = this.getStandardComplaints(); List<String> complaintSubmitValues = this.getComplaintSubmitValues(); Iterator<String> standard = standardComplaints.iterator(); Iterator<String> submit = complaintSubmitValues.iterator(); complaintsMap = new HashMap<String, String>(); //standard.next(); submit.next(); //skip the first item 'select a complaint' while (standard.hasNext() && submit.hasNext()) complaintsMap.put(standard.next().toString(), submit.next().toString()); // set up complaint spinner List<String> complaints_list = this.getStandardComplaints(); complaintSpinner = (Spinner) findViewById(R.id.complaint_spinner); complaintsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, complaints_list);//from w w w. j a v a2 s .c om complaintsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); complaintSpinner.setAdapter(complaintsAdapter); complaintSpinner.setOnItemSelectedListener(this); complaintSpinner.setOnItemLongClickListener(this);// this doesn't actually work yet bc not supported by API - events don't get fired //attach location listener to button findViewById(R.id.location_button).setOnClickListener(this); // make link in disclaimer clickable TextView disclaimer = (TextView) findViewById(R.id.disclaimer_textview); disclaimer.setMovementMethod(LinkMovementMethod.getInstance()); // check &or load shared preferences to populate saved personal information mPersonalInfo = new PersonalInfo(); SharedPreferences preferences = getPreferences(MODE_PRIVATE); mPersonalInfo.loadFromPreferences(preferences); // suppress keyboard this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); // set complaint location to multiline for large layouts if (findViewById(R.id.layout_large_land) != null || findViewById(R.id.layout_large) != null) { ((EditText) findViewById(R.id.complaint_address)).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_WORDS); } }
From source file:de.eidottermihi.rpicheck.activity.NewRaspiAuthActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_raspi_new_auth); // Show the Up button in the action bar. getSupportActionBar().setDisplayHomeAsUpEnabled(true); // show default option for auth method = ssh password this.switchAuthMethodsInView(SPINNER_AUTH_METHODS[0]); // init auth spinner final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.auth_methods, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinnerAuth.setAdapter(adapter);/*from ww w.j a v a 2 s. c om*/ spinnerAuth.setOnItemSelectedListener(this); // init sql db deviceDb = new DeviceDbHelper(this); // get data from previous screen (name/host/user...), already validated final Bundle piData = this.getIntent().getExtras().getBundle(NewRaspiActivity.PI_BUNDLE); host = piData.getString(NewRaspiActivity.PI_HOST); name = piData.getString(NewRaspiActivity.PI_NAME); user = piData.getString(NewRaspiActivity.PI_USER); desc = piData.getString(NewRaspiActivity.PI_DESC); }
From source file:org.openoverlayrouter.noroot.updateConfActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { faActivity = (FragmentActivity) super.getActivity(); llLayout = (LinearLayout) inflater.inflate(R.layout.updateconf2, container, false); setTextHintAlphas();/* w ww. ja v a 2s .c o m*/ conf_file = new File(sdcardDir, confFile); log_file = sdcardDir.getAbsolutePath() + "/oor.log"; iface_list = ConfigTools.get_ifaces_list(); MultiSelectionSpinner spinner = (MultiSelectionSpinner) llLayout.findViewById(R.id.IfaceNameSpinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(faActivity, android.R.layout.simple_spinner_item, iface_list); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setItems(iface_list); Spinner logSpinner = (Spinner) llLayout.findViewById(R.id.LogSpinner); ArrayAdapter<CharSequence> logAdapter = ArrayAdapter.createFromResource(faActivity, R.array.LogLevelArray, android.R.layout.simple_spinner_item); logSpinner.setAdapter(logAdapter); if (!conf_file.exists()) { createConfFile(); } readConfFileAndFillParameters(); Button updateConfButton = (Button) llLayout.findViewById(R.id.updateConfButton); updateConfButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { updateConfClicked(llLayout); } }); CheckBox updateConf_NAT_aware = (CheckBox) llLayout.findViewById(R.id.updateConf_NAT_aware); updateConf_NAT_aware.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { updateConfNATAwareClicked(llLayout); } }); CheckBox updateCondDNSCheck = (CheckBox) llLayout.findViewById(R.id.updateConfDNSCheck); updateCondDNSCheck.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { updateConfDNSClicked(llLayout); } }); return llLayout; }
From source file:org.onebusaway.android.report.ui.ReportTripProblemFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { // Set the stop name. Bundle args = getArguments();// w w w . j a v a 2 s. co m final TextView tripHeadsign = (TextView) view.findViewById(R.id.report_problem_headsign); tripHeadsign.setText(UIUtils.formatDisplayText(args.getString(TRIP_HEADSIGN))); // TODO: Switch this based on the trip mode final int tripArray = R.array.report_trip_problem_code_bus; // // The code spinner // mCodeView = (Spinner) view.findViewById(R.id.report_problem_code); ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(getActivity(), tripArray, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mCodeView.setAdapter(adapter); // Comment mUserComment = (TextView) view.findViewById(R.id.report_problem_comment); // On vehicle mUserOnVehicle = (CheckBox) view.findViewById(R.id.report_problem_onvehicle); mUserVehicle = (EditText) view.findViewById(R.id.report_problem_uservehicle); // Disabled by default mUserVehicle.setEnabled(false); mUserOnVehicle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = mUserOnVehicle.isChecked(); mUserVehicle.setEnabled(checked); } }); if (savedInstanceState != null) { int position = savedInstanceState.getInt(CODE); mCodeView.setSelection(position); CharSequence comment = savedInstanceState.getCharSequence(USER_COMMENT); mUserComment.setText(comment); boolean onVehicle = savedInstanceState.getBoolean(USER_ON_VEHICLE); mUserOnVehicle.setChecked(onVehicle); CharSequence num = savedInstanceState.getCharSequence(USER_VEHICLE_NUM); mUserVehicle.setText(num); mUserVehicle.setEnabled(onVehicle); } SPINNER_TO_CODE = new String[] { null, ObaReportProblemWithTripRequest.VEHICLE_NEVER_CAME, ObaReportProblemWithTripRequest.VEHICLE_CAME_EARLY, ObaReportProblemWithTripRequest.VEHICLE_CAME_LATE, ObaReportProblemWithTripRequest.WRONG_HEADSIGN, ObaReportProblemWithTripRequest.VEHICLE_DOES_NOT_STOP_HERE, ObaReportProblemWithTripRequest.OTHER }; setupIconColors(); }
From source file:de.eidottermihi.rpicheck.activity.EditRaspiActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_raspi_edit); // Show the Up button in the action bar. getSupportActionBar().setDisplayHomeAsUpEnabled(true); // init sql db deviceDb = new DeviceDbHelper(this); // read device information int deviceId = this.getIntent().getExtras().getInt(Constants.EXTRA_DEVICE_ID); deviceBean = deviceDb.read(deviceId); // init auth spinner final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.auth_methods, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinnerAuth.setAdapter(adapter);//from w w w.j ava 2 s . c o m spinnerAuth.setOnItemSelectedListener(this); if (deviceBean.getAuthMethod().equals(NewRaspiAuthActivity.SPINNER_AUTH_METHODS[0])) { spinnerAuth.setSelection(0); } else if (deviceBean.getAuthMethod().equals(NewRaspiAuthActivity.SPINNER_AUTH_METHODS[1])) { spinnerAuth.setSelection(1); } else { spinnerAuth.setSelection(2); } // fill fields according to data from device bean fillFromBean(); }
From source file:org.gnucash.android.export.ExportDialogFragment.java
/** * Collects references to the UI elements and binds click listeners *///from w ww . j ava 2 s .c o m private void bindViews() { View v = getView(); mDestinationSpinner = (Spinner) v.findViewById(R.id.spinner_export_destination); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.export_destinations, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDestinationSpinner.setAdapter(adapter); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mExportAllCheckBox = (CheckBox) v.findViewById(R.id.checkbox_export_all); mExportAllCheckBox .setChecked(sharedPrefs.getBoolean(getString(R.string.key_export_all_transactions), false)); mDeleteAllCheckBox = (CheckBox) v.findViewById(R.id.checkbox_post_export_delete); mDeleteAllCheckBox.setChecked( sharedPrefs.getBoolean(getString(R.string.key_delete_transactions_after_export), false)); mSaveButton = (Button) v.findViewById(R.id.btn_save); mSaveButton.setText(R.string.btn_export); mCancelButton = (Button) v.findViewById(R.id.btn_cancel); mCancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); mSaveButton.setOnClickListener(new ExportClickListener()); String defaultExportFormat = sharedPrefs.getString(getString(R.string.key_default_export_format), ExportFormat.QIF.name()); mExportFormat = ExportFormat.valueOf(defaultExportFormat); View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View view) { onRadioButtonClicked(view); } }; RadioButton ofxRadioButton = (RadioButton) v.findViewById(R.id.radio_ofx_format); ofxRadioButton.setChecked(defaultExportFormat.equalsIgnoreCase(ExportFormat.OFX.name())); ofxRadioButton.setOnClickListener(clickListener); RadioButton qifRadioButton = (RadioButton) v.findViewById(R.id.radio_qif_format); qifRadioButton.setChecked(defaultExportFormat.equalsIgnoreCase(ExportFormat.QIF.name())); qifRadioButton.setOnClickListener(clickListener); }
From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.socialmedia.twitter.TwitterFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_recycler_with_spinner_swipe_refresh, null); mRecyclerView = root.findViewById(R.id.my_recycler_view); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(getActivity()); mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new TwitterItemAdapter(null); mRecyclerView.setAdapter(mAdapter);/*from w w w . jav a 2s.c om*/ // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity. root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); swipeRefreshLayout = root.findViewById(R.id.swipe_container); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); mEmptyView = root.findViewById(R.id.empty_list_view); Spinner spinner = root.findViewById(R.id.fragment_spinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.twitter_accounts, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); viewModel = ViewModelProviders.of(this, viewModelFactory).get(TwitterViewModel.class); viewModel.getResourceStatus().observe(this, resourceStatus -> { if (resourceStatus != null) { switch (resourceStatus.status) { case LOADING: swipeRefreshLayout.setRefreshing(true); break; case SUCCESS: swipeRefreshLayout.setRefreshing(false); break; case ERROR: swipeRefreshLayout.setRefreshing(false); TextView t = (TextView) mEmptyView; t.setText(R.string.no_connection); mEmptyView.setVisibility(View.VISIBLE); Toast.makeText(getContext(), "connection error", Toast.LENGTH_SHORT).show(); } } }); viewModel.getTwitterPosts().observe(this, twitterItems -> { if (twitterItems != null) { mEmptyView.setVisibility(View.GONE); if (!twitterItems.isEmpty()) { mAdapter.setData(twitterItems); } else { TextView t = (TextView) mEmptyView; t.setText("tweets unavailable."); mEmptyView.setVisibility(View.VISIBLE); } } }); viewModel.refresh(); return root; }
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 om*/ 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; }