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:org.onebusaway.android.ui.ReportStopProblemFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { // Set the stop name. Bundle args = getArguments();// w ww . jav a2 s. c o m final TextView stopName = (TextView) view.findViewById(R.id.stop_name); stopName.setText(MyTextUtils.toTitleCase(args.getString(STOP_NAME))); // // The code spinner // mCodeView = (Spinner) view.findViewById(R.id.report_problem_code); ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.report_stop_problem_code, 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); if (savedInstanceState != null) { int position = savedInstanceState.getInt(CODE); mCodeView.setSelection(position); CharSequence comment = savedInstanceState.getCharSequence(USER_COMMENT); mUserComment.setText(comment); } SPINNER_TO_CODE = new String[] { null, ObaReportProblemWithStopRequest.NAME_WRONG, ObaReportProblemWithStopRequest.NUMBER_WRONG, ObaReportProblemWithStopRequest.LOCATION_WRONG, ObaReportProblemWithStopRequest.ROUTE_OR_TRIP_MISSING, ObaReportProblemWithStopRequest.OTHER }; }
From source file:net.wespot.pim.utils.layout.NoticeDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.dialog_create_data_collection_task, null); builder.setView(view);/*from w ww . j a v a 2 s.c om*/ dialog_title = (EditText) view.findViewById(R.id.data_collection_dialog_title); dialog_description = (EditText) view.findViewById(R.id.data_collection_dialog_description); dialog_type_dc = (Spinner) view.findViewById(R.id.data_collection_dialog_type); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.data_collection_type, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(R.layout.spinner_layout); // Apply the adapter to the spinner dialog_type_dc.setAdapter(adapter); dialog_type_dc.setOnItemSelectedListener(this); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setPositiveButton(R.string.data_collection_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent a = getActivity().getIntent(); a.putExtra(TITLE, dialog_title.getText()); a.putExtra(DESCRIPTION, dialog_description.getText()); setTitle(dialog_title.getText().toString()); setDescription(dialog_description.getText().toString()); setAudio(audio); setVideo(video); setImage(image); setText(text); setNumber(number); getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, a); } }).setNegativeButton(R.string.data_collection_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_CANCELED, getActivity().getIntent()); } }); return builder.create(); }
From source file:open.currency.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setToolbarEnabled(true);/*from w ww. j av a 2s . co m*/ String desGithub = "Visit the <a href='http://openappsproject.github.io/OpenCurrency/'>project page</a> to get more information about OpenCurrency.<br/><br/> 2015 - 2016 OpenAppsProject"; TextView desTV = (TextView) findViewById(R.id.link_github); desTV.setLinksClickable(true); desTV.setMovementMethod(LinkMovementMethod.getInstance()); desTV.setText(Html.fromHtml(desGithub)); currencyArray = getResources().getStringArray(R.array.currencies); currency1 = (EditText) findViewById(R.id.currency1); currency2 = (EditText) findViewById(R.id.currency2); tilCur1 = (TextInputLayout) findViewById(R.id.tilCur1); tilCur2 = (TextInputLayout) findViewById(R.id.tilCur2); Spinner spinner1 = (Spinner) findViewById(R.id.spinner1); Spinner spinner2 = (Spinner) findViewById(R.id.spinner2); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.currencies, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); lastEdited = 1; currency1.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { lastEdited = 1; } }); currency2.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { lastEdited = 2; } }); spinner1.setAdapter(adapter); spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { cur1 = position; tilCur1.setHint(currencyArray[position]); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spinner2.setAdapter(adapter); spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { cur2 = position; tilCur2.setHint(currencyArray[position]); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); setFabEnabled(true); setFabDrawable(ContextCompat.getDrawable(this, R.drawable.ic_check_white_48dp)); setFabListener(new View.OnClickListener() { Double inputValue = Double.valueOf("0"); @Override public void onClick(View v) { currency1.setEnabled(false); currency2.setEnabled(false); try { if (lastEdited == 1) { inputValue = Double.valueOf(currency1.getText().toString()); } else { inputValue = Double.valueOf(currency2.getText().toString()); } } catch (Exception e) { e.printStackTrace(); } if (inputValue.equals(Double.valueOf("0"))) { Snackbar.make(v, R.string.empty_value, Snackbar.LENGTH_LONG).show(); currency1.setEnabled(true); currency2.setEnabled(true); } else if (cur1 == cur2) { Snackbar.make(v, R.string.sam_cur, Snackbar.LENGTH_LONG).show(); currency1.setEnabled(true); currency2.setEnabled(true); } else { Action<Double> doCalculate = new Action<Double>() { @NonNull @Override public String id() { return "calculate"; } @Nullable @Override protected Double run() throws InterruptedException { if (lastEdited == 1) { return calculate(currencyArray[cur1], currencyArray[cur2], inputValue); } else { return calculate(currencyArray[cur2], currencyArray[cur1], inputValue); } } @Override protected void done(@Nullable Double result) { if (result != null) { if (lastEdited == 1) { currency2.setText(String.valueOf(result)); } else { currency1.setText(String.valueOf(result)); } } currency1.setEnabled(true); currency2.setEnabled(true); } }; doCalculate.execute(); } } }); }
From source file:com.actionbarsherlock.sample.styled.MainActivityICS.java
/** Called when the activity is first created. */ @Override/*from w ww. java 2 s .c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.main); final ActionBar ab = getActionBar(); // set defaults for logo & home up ab.setDisplayHomeAsUpEnabled(showHomeUp); ab.setDisplayUseLogoEnabled(useLogo); // set up tabs nav for (int i = 1; i < 4; i++) { ab.addTab(ab.newTab().setText("Tab " + i).setTabListener(this)); } // set up list nav ab.setListNavigationCallbacks( ArrayAdapter.createFromResource(ab.getThemedContext(), R.array.sections, android.R.layout.simple_spinner_dropdown_item), // .createFromResource(this, R.array.sections, // android.R.layout.simple_spinner_dropdown_item), new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { // FIXME add proper implementation //rotateLeftFrag(); return false; } }); // default to tab navigation showTabsNav(); // create a couple of simple fragments as placeholders // final int MARGIN = 16; // leftFrag = new RoundedColourFragment(getResources().getColor( // R.color.android_green), 1f, MARGIN, MARGIN / 2, MARGIN, MARGIN); // rightFrag = new RoundedColourFragment(getResources().getColor( // R.color.honeycombish_blue), 2f, MARGIN / 2, MARGIN, MARGIN, // MARGIN); // // FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); // ft.add(R.id.root, leftFrag); // ft.add(R.id.root, rightFrag); // ft.commit(); ((Button) findViewById(R.id.start)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mMode = startActionMode(new AnActionModeOfEpicProportions()); } }); ((Button) findViewById(R.id.cancel)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mMode != null) { mMode.finish(); } } }); ((Button) findViewById(R.id.progress)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mProgress == 100) { mProgress = 0; mProgressRunner.run(); } } }); }
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 w w .j a va2 s . 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.teleca.jamendo.activity.SearchActivity.java
/** Called when the activity is first created. */ @SuppressWarnings("unchecked") @Override//from ww w .j a v a 2 s . com public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.search); mSearchSpinner = (Spinner) findViewById(R.id.SearchSpinner); ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.search_modes, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSearchSpinner.setAdapter(adapter); mSearchButton = (Button) findViewById(R.id.SearchButton); mSearchButton.setOnClickListener(mSearchButtonListener); mSearchEditText = (EditText) findViewById(R.id.SearchEditText); mSearchListView = (ListView) findViewById(R.id.SearchListView); mViewFlipper = (ViewFlipper) findViewById(R.id.SearchViewFlipper); if (mSearchListView.getCount() == 0) { mViewFlipper.setDisplayedChild(2); // search list hint } mGestureOverlayView = (GestureOverlayView) findViewById(R.id.gestures); mGestureOverlayView .addOnGesturePerformedListener(JamendoApplication.getInstance().getPlayerGestureHandler()); }
From source file:org.onebusaway.android.report.ui.ReportStopProblemFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { // The code spinner mCodeView = (Spinner) view.findViewById(R.id.report_problem_code); ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.report_stop_problem_code, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mCodeView.setAdapter(adapter);//from w w w . ja v a 2 s . com // Comment mUserComment = (TextView) view.findViewById(R.id.report_problem_comment); if (savedInstanceState != null) { int position = savedInstanceState.getInt(CODE); mCodeView.setSelection(position); CharSequence comment = savedInstanceState.getCharSequence(USER_COMMENT); mUserComment.setText(comment); } SPINNER_TO_CODE = new String[] { null, ObaReportProblemWithStopRequest.NAME_WRONG, ObaReportProblemWithStopRequest.NUMBER_WRONG, ObaReportProblemWithStopRequest.LOCATION_WRONG, ObaReportProblemWithStopRequest.ROUTE_OR_TRIP_MISSING, ObaReportProblemWithStopRequest.OTHER }; // Dynamically change the color of the small icons setupIconColors(); }
From source file:cc.siara.csv_ml_demo.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set event handlers setContentView(R.layout.activity_main); Button btnXML = (Button) findViewById(R.id.btnXML); btnXML.setOnClickListener(this); Button btnJSON = (Button) findViewById(R.id.btnJSON); btnJSON.setOnClickListener(this); Button btnXPath = (Button) findViewById(R.id.btnXPath); btnXPath.setOnClickListener(this); Button btnDDLDML = (Button) findViewById(R.id.btnDDLDML); btnDDLDML.setOnClickListener(this); Button btnXMLtoCSV = (Button) findViewById(R.id.btnXMLtoCSV); btnXMLtoCSV.setOnClickListener(this); Spinner spinner = (Spinner) findViewById(R.id.spExamples); spinner.setOnItemSelectedListener(this); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.input_examples, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter);//w w w . j a v a 2 s. co m }
From source file:co.carlosjimenez.android.currencyalerts.app.AddAlertFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_add_alarm, null); ButterKnife.bind(this, dialogView); Bundle arguments = getArguments();// ww w. j a v a 2s . c o m if (arguments != null) { mCurrencyFrom = arguments.getParcelable(DetailActivityFragment.CURRENCY_FROM); mCurrencyTo = arguments.getParcelable(DetailActivityFragment.CURRENCY_TO); } ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.alarm_period_labels, R.layout.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 mSpPeriod.setAdapter(adapter); alertValues = Utility.getAlertSettings(getContext(), false); if (alertValues.getCurrencyFrom().equals(mCurrencyFrom) && alertValues.getCurrencyTo().equals(mCurrencyTo)) { setSelectedPeriod(String.valueOf(alertValues.getPeriod())); mTvFluctuation.setText(String.valueOf(alertValues.getFluctuation())); } else { alertValues = Utility.getAlertSettings(getContext(), true); alertValues.clearAverage(); } // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(dialogView) // Add action buttons .setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { alertValues.setEnabled(true); alertValues.setCurrencyFrom(mCurrencyFrom); alertValues.setCurrencyTo(mCurrencyTo); alertValues.setPeriod(Integer.parseInt(mSelectedPeriod)); alertValues.setFluctuation(Float.parseFloat(mTvFluctuation.getText().toString())); new UpdateAlarmTask(getActivity()).execute(alertValues); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { AddAlertFragment.this.getDialog().cancel(); } }); AlertDialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); return alertDialog; }
From source file:com.asksven.betterbatterystats.RawStatsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.raw_stats);/*from w w w. j a va 2 s .c om*/ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(getString(R.string.label_raw_stats)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayUseLogoEnabled(false); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { doRefresh(); } }); // Spinner for selecting the stat Spinner spinnerStat = (Spinner) findViewById(R.id.spinnerStat); ArrayAdapter spinnerStatAdapter = ArrayAdapter.createFromResource(this, R.array.stats, R.layout.bbs_spinner_layout); spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); spinnerStat.setAdapter(spinnerStatAdapter); // setSelection MUST be called after setAdapter spinnerStat.setSelection(m_iStat); spinnerStat.setOnItemSelectedListener(this); TextView tvSince = (TextView) findViewById(R.id.TextViewSince); long sinceMs = SystemClock.elapsedRealtime(); if (sinceMs != -1) { String sinceText = DateUtils.formatDuration(sinceMs); tvSince.setText(sinceText); Log.i(TAG, "Since " + sinceText); } else { tvSince.setText("n/a "); Log.i(TAG, "Since: n/a "); } }