List of usage examples for android.widget Spinner setAdapter
@Override public void setAdapter(SpinnerAdapter adapter)
From source file:ca.ualberta.slevinsk.gameshow.ReactionStatsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final List<String> test = new ArrayList<>(); final ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.list_item, test); setListAdapter(adapter);//from w ww . j a va 2 s . c o m final Spinner spinner = (Spinner) getView().findViewById(R.id.spinner); ArrayList<SpecialPair<String, Integer>> test2 = new ArrayList<>(); test2.add(new SpecialPair<String, Integer>("Last 10", 10)); test2.add(new SpecialPair<String, Integer>("Last 100", 100)); test2.add(new SpecialPair<String, Integer>("All", -1)); ArrayAdapter<SpecialPair<String, Integer>> adapter2 = new ArrayAdapter<>(getContext(), R.layout.list_item, test2); Generator<List, Integer> dataGenerator = new Generator<List, Integer>() { @Override public List generate(Integer arg) { return ReactionTimersController.generateStatsData(arg); } }; SpinListener listener = new SpinListener(spinner, test, adapter, dataGenerator); spinner.setAdapter(adapter2); spinner.setOnItemSelectedListener(listener); ReactionTimersController.getReactionTimerList().addListener(listener); }
From source file:com.google.firebase.samples.apps.mlkit.LivePreviewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); setContentView(R.layout.activity_live_preview); preview = (CameraSourcePreview) findViewById(R.id.firePreview); if (preview == null) { Log.d(TAG, "Preview is null"); }/* ww w . ja va 2 s . c om*/ graphicOverlay = (GraphicOverlay) findViewById(R.id.fireFaceOverlay); if (graphicOverlay == null) { Log.d(TAG, "graphicOverlay is null"); } Spinner spinner = (Spinner) findViewById(R.id.spinner); List<String> options = new ArrayList<>(); options.add(FACE_DETECTION); options.add(TEXT_DETECTION); options.add(BARCODE_DETECTION); options.add(IMAGE_LABEL_DETECTION); options.add(CLASSIFICATION); // Creating adapter for spinner ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, R.layout.spinner_style, options); // Drop down layout style - list view with radio button dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // attaching data adapter to spinner spinner.setAdapter(dataAdapter); spinner.setOnItemSelectedListener(this); ToggleButton facingSwitch = (ToggleButton) findViewById(R.id.facingswitch); facingSwitch.setOnCheckedChangeListener(this); if (allPermissionsGranted()) { createCameraSource(selectedModel); } else { getRuntimePermissions(); } }
From source file:edu.cmu.hcii.hangg.beeksbeacon.Fragments.ManageBeaconFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.i(TAG, "bi.id: " + beaconInstance.id + ", bi.googleType: " + beaconInstance.googleType); View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false); advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type); advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id); status = (TextView) rootView.findViewById(R.id.status); placeId = (TextView) rootView.findViewById(R.id.placeId); placeId.setOnClickListener(new View.OnClickListener() { @Override//from w w w . j av a 2 s. c o m public void onClick(View v) { editLatLngAction(); } }); latLng = (TextView) rootView.findViewById(R.id.latLng); latLng.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); mapView = (ImageView) rootView.findViewById(R.id.mapView); mapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); expectedStability = (TextView) rootView.findViewById(R.id.expectedStability); expectedStability.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability"); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.stability_enums, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner spinner = new Spinner(getActivity()); spinner.setAdapter(adapter); // Set the position of the spinner to the current value. if (beaconInstance.expectedStability != null && !beaconInstance.expectedStability.equals(BeaconInstance.STABILITY_UNSPECIFIED)) { for (int i = 0; i < spinner.getCount(); i++) { if (beaconInstance.expectedStability.equals(spinner.getItemAtPosition(i))) { spinner.setSelection(i); } } } builder.setView(spinner); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beaconInstance.expectedStability = (String) spinner.getSelectedItem(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); description = (TextView) rootView.findViewById(R.id.description); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description"); final EditText editText = new EditText(getActivity()); editText.setText(description.getText()); builder.setView(editText); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beaconInstance.description = editText.getText().toString(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); actionButton = (Button) rootView.findViewById(R.id.actionButton); decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton); decommissionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon") .setMessage("Are you sure you want to decommission this beacon? This operation is " + "irreversible and the beacon cannot be registered again") .setPositiveButton("Decommission", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Callback decommissionCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { beaconInstance.status = BeaconInstance.STATUS_DECOMMISSIONED; updateBeacon(); } else { String body = response.body().string(); logErrorAndToast("Unsuccessful decommissionBeacon request: " + body); } } }; client.decommissionBeacon(decommissionCallback, beaconInstance.getBeaconName()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }); attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider); attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel); attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout); // Fetch the namespace for the developer console project ID. We redraw the UI once that // request completes. // TODO: cache this. Callback listNamespacesCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); if (response.isSuccessful()) { try { JSONObject json = new JSONObject(body); JSONArray namespaces = json.getJSONArray("namespaces"); // At present there can be only one namespace. String tmp = namespaces.getJSONObject(0).getString("namespaceName"); if (tmp.startsWith("namespaces/")) { namespace = tmp.substring("namespaces/".length()); } else { namespace = tmp; } redraw(); } catch (JSONException e) { Log.e(TAG, "JSONException", e); } } else { logErrorAndToast("Unsuccessful listNamespaces request: " + body); } } }; client.listNamespaces(listNamespacesCallback); return rootView; }
From source file:gr.scify.newsum.ui.SearchViewActivity.java
private void initTopicSpinner() { // Get topics in category. Null accepts all user sources. Modify // according to user selection final String[] saTopicIDs = SearchTopicActivity.saTopicIDs; final String[] saTitles = SearchTopicActivity.saTopicTitles; final String[] saDates = SearchTopicActivity.saTopicDates; // TODO add TopicInfo for SearchResults as well and parse accordingly // final String[] saTopicIDs = extras.getStringArray("searchresults"); final TextView title = (TextView) findViewById(R.id.title); // Fill topic spinner ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, saTitles); final TextView tx = (TextView) findViewById(R.id.textView1); // tx.setMovementMethod(LinkMovementMethod.getInstance()); // final float minm = tx.getTextSize(); // final float maxm = (minm + 24); // create an invisible spinner just to control the summaries of the // category (i will use it later on Swipe) Spinner spinner = (Spinner) findViewById(R.id.spinner1); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); // Scroll view init final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1); // Add selection event spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Show waiting dialog showWaitingDialog();/* w w w . j a va 2 s . com*/ // Changing summary loading = true; // Update visibility of rating bar final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar); rb.setRating(0.0f); rb.setVisibility(View.VISIBLE); final TextView rateLbl = (TextView) findViewById(R.id.rateLbl); rateLbl.setVisibility(View.VISIBLE); scroll.scrollTo(0, 0); // String[] saTopicIDs = sTopicIds.split(sSeparator); SharedPreferences settings = getSharedPreferences("urls", 0); // get user settings for sources String UserSources = settings.getString("UserLinks", "All"); String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources); if (Summary.length == 0) { // WORK. Updated: CHECK // Close waiting dialog closeWaitingDialog(); AlertDialog.Builder alert = new AlertDialog.Builder(SearchViewActivity.this); alert.setMessage(R.string.shouldReloadSummaries); alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); } }); alert.setCancelable(false); alert.show(); loading = false; return; } // track summary views per Search and topic title if (getAnalyticsPref()) { EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, "From Search", saTitles[arg2] + ": " + saDates[arg2], 0l); } // Generate summary text sText = ViewActivity.generateSummaryText(Summary, SearchViewActivity.this); pText = ViewActivity.generatesummarypost(Summary, SearchViewActivity.this); tx.setText(Html.fromHtml(sText)); tx.setMovementMethod(LinkMovementMethod.getInstance()); title.setText(saTitles[arg2] + ": " + saDates[arg2]); float defSize = tx.getTextSize(); SharedPreferences usersize = getSharedPreferences("textS", 0); float newSize = usersize.getFloat("size", defSize); tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize); // update the TopicActivity with viewed item TopicActivity.addVisitedTopicID(saTopicIDs[arg2]); // Close waiting dialog closeWaitingDialog(); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); }
From source file:com.example.accountkitsample.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (AccountKit.getCurrentAccessToken() != null) { showHelloActivity(null);//from ww w . j a va 2s . c o m } final Spinner themeSpinner = (Spinner) findViewById(R.id.theme_spinner); if (themeSpinner != null) { final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.theme_options, android.R.layout.simple_spinner_dropdown_item); themeSpinner.setAdapter(adapter); themeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { switch (position) { case 0: selectedThemeId = R.style.AppLoginTheme; break; case 1: selectedThemeId = R.style.AppLoginTheme_Salmon; break; case 2: selectedThemeId = R.style.AppLoginTheme_Yellow; break; case 3: selectedThemeId = R.style.AppLoginTheme_Red; break; case 4: selectedThemeId = R.style.AppLoginTheme_Dog; break; case 5: selectedThemeId = R.style.AppLoginTheme_Bicycle; break; case 6: selectedThemeId = R.style.AppLoginTheme_Reverb_A; advancedUISwitch.setChecked(true); break; case 7: selectedThemeId = R.style.AppLoginTheme_Reverb_B; advancedUISwitch.setChecked(true); break; case 8: selectedThemeId = R.style.AppLoginTheme_Reverb_C; advancedUISwitch.setChecked(true); break; default: selectedThemeId = -1; break; } } @Override public void onNothingSelected(final AdapterView<?> parent) { selectedThemeId = -1; } }); } advancedUISwitch = (Switch) findViewById(R.id.advanced_ui_switch); final MainActivity thisActivity = this; final LinearLayout advancedUIOptionsLayout = (LinearLayout) findViewById(R.id.advanced_ui_options); final List<CharSequence> buttonNames = new ArrayList<>(); buttonNames.add("Default"); for (ButtonType buttonType : ButtonType.values()) { buttonNames.add(buttonType.name()); } final ArrayAdapter<CharSequence> buttonNameAdapter = new ArrayAdapter<>(thisActivity, android.R.layout.simple_spinner_dropdown_item, buttonNames); advancedUISwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { advancedUIOptionsLayout.setVisibility(View.VISIBLE); final Spinner entryButtonSpinner = (Spinner) findViewById(R.id.entry_button_spinner); if (entryButtonSpinner != null) { entryButtonSpinner.setAdapter(buttonNameAdapter); entryButtonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { // First position is empty, so anything past that if (position > 0) { entryButton = ButtonType .valueOf(entryButtonSpinner.getSelectedItem().toString()); } else { entryButton = null; } } @Override public void onNothingSelected(final AdapterView<?> parent) { entryButton = null; } }); } final Spinner confirmButtonSpinner = (Spinner) findViewById(R.id.confirm_button_spinner); if (confirmButtonSpinner != null) { confirmButtonSpinner.setAdapter(buttonNameAdapter); confirmButtonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { // First position is empty, so anything past // that if (position > 0) { confirmButton = ButtonType .valueOf(confirmButtonSpinner.getSelectedItem().toString()); } else { confirmButton = null; } } @Override public void onNothingSelected(final AdapterView<?> parent) { confirmButton = null; } }); } final Spinner textPositionSpinner = (Spinner) findViewById(R.id.text_position_spinner); if (textPositionSpinner != null) { final List<CharSequence> textPositions = new ArrayList<>(); textPositions.add("Default"); for (TextPosition textPosition : TextPosition.values()) { textPositions.add(textPosition.name()); } final ArrayAdapter<CharSequence> textPositionAdapter = new ArrayAdapter<>(thisActivity, android.R.layout.simple_spinner_dropdown_item, textPositions); textPositionSpinner.setAdapter(textPositionAdapter); textPositionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { // First position is empty, so anything past // that if (position > 0) { textPosition = TextPosition .valueOf(textPositionSpinner.getSelectedItem().toString()); } else { textPosition = null; } } @Override public void onNothingSelected(final AdapterView<?> parent) { textPosition = null; } }); } } else if (isReverbThemeSelected()) { advancedUISwitch.setChecked(true); Toast.makeText(MainActivity.this, R.string.reverb_advanced_ui_required, Toast.LENGTH_LONG) .show(); } else { advancedUIOptionsLayout.setVisibility(View.GONE); } } }); }
From source file:com.facebook.samples.loginsample.accountkit.AccountKitLoginActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.account_kit_activity); if (AccountKit.getCurrentAccessToken() != null) { showHelloActivity(null);/*from w w w . j a va 2 s .c o m*/ } final Spinner themeSpinner = (Spinner) findViewById(R.id.theme_spinner); if (themeSpinner != null) { final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.theme_options, android.R.layout.simple_spinner_dropdown_item); themeSpinner.setAdapter(adapter); themeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { switch (position) { case 0: selectedThemeId = R.style.AppLoginTheme; break; case 1: selectedThemeId = R.style.AppLoginTheme_Salmon; break; case 2: selectedThemeId = R.style.AppLoginTheme_Yellow; break; case 3: selectedThemeId = R.style.AppLoginTheme_Red; break; case 4: selectedThemeId = R.style.AppLoginTheme_Dog; break; case 5: selectedThemeId = R.style.AppLoginTheme_Bicycle; break; case 6: selectedThemeId = R.style.AppLoginTheme_Reverb_A; advancedUISwitch.setChecked(true); break; case 7: selectedThemeId = R.style.AppLoginTheme_Reverb_B; advancedUISwitch.setChecked(true); break; case 8: selectedThemeId = R.style.AppLoginTheme_Reverb_C; advancedUISwitch.setChecked(true); break; default: selectedThemeId = -1; break; } } @Override public void onNothingSelected(final AdapterView<?> parent) { selectedThemeId = -1; } }); } advancedUISwitch = (Switch) findViewById(R.id.advanced_ui_switch); final AccountKitLoginActivity thisActivity = this; final LinearLayout advancedUIOptionsLayout = (LinearLayout) findViewById(R.id.advanced_ui_options); final List<CharSequence> buttonNames = new ArrayList<>(); buttonNames.add("Default"); for (ButtonType buttonType : ButtonType.values()) { buttonNames.add(buttonType.name()); } final ArrayAdapter<CharSequence> buttonNameAdapter = new ArrayAdapter<>(thisActivity, android.R.layout.simple_spinner_dropdown_item, buttonNames); advancedUISwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { advancedUIOptionsLayout.setVisibility(View.VISIBLE); final Spinner entryButtonSpinner = (Spinner) findViewById(R.id.entry_button_spinner); if (entryButtonSpinner != null) { entryButtonSpinner.setAdapter(buttonNameAdapter); entryButtonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { // First position is empty, so anything past that if (position > 0) { entryButton = ButtonType .valueOf(entryButtonSpinner.getSelectedItem().toString()); } else { entryButton = null; } } @Override public void onNothingSelected(final AdapterView<?> parent) { entryButton = null; } }); } final Spinner confirmButtonSpinner = (Spinner) findViewById(R.id.confirm_button_spinner); if (confirmButtonSpinner != null) { confirmButtonSpinner.setAdapter(buttonNameAdapter); confirmButtonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { // First position is empty, so anything past // that if (position > 0) { confirmButton = ButtonType .valueOf(confirmButtonSpinner.getSelectedItem().toString()); } else { confirmButton = null; } } @Override public void onNothingSelected(final AdapterView<?> parent) { confirmButton = null; } }); } final Spinner textPositionSpinner = (Spinner) findViewById(R.id.text_position_spinner); if (textPositionSpinner != null) { final List<CharSequence> textPositions = new ArrayList<>(); textPositions.add("Default"); for (TextPosition textPosition : TextPosition.values()) { textPositions.add(textPosition.name()); } final ArrayAdapter<CharSequence> textPositionAdapter = new ArrayAdapter<>(thisActivity, android.R.layout.simple_spinner_dropdown_item, textPositions); textPositionSpinner.setAdapter(textPositionAdapter); textPositionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) { // First position is empty, so anything past // that if (position > 0) { textPosition = TextPosition .valueOf(textPositionSpinner.getSelectedItem().toString()); } else { textPosition = null; } } @Override public void onNothingSelected(final AdapterView<?> parent) { textPosition = null; } }); } } else if (isReverbThemeSelected()) { advancedUISwitch.setChecked(true); Toast.makeText(AccountKitLoginActivity.this, R.string.reverb_advanced_ui_required, Toast.LENGTH_LONG).show(); } else { advancedUIOptionsLayout.setVisibility(View.GONE); } } }); }
From source file:com.teitsmch.hearthmaker.MainActivity.java
private void setSpinnerAdapter(Spinner currentSpinner, int arrayId) { ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arrayId, R.layout.spinner_item); adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); currentSpinner.setAdapter(adapter); }
From source file:ca.marcmeszaros.papyrus.fragments.BooksListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Spinner spinner = (Spinner) getView().findViewById(R.id.BooksBrowser_spinner_library); getListView().setOnItemClickListener(this); getListView().setOnItemLongClickListener((OnItemLongClickListener) getActivity()); spinner.setOnItemSelectedListener((OnItemSelectedListener) getActivity()); books = new BookAdapter(getActivity(), null); setListAdapter(books);// w w w .j a v a 2 s . c o m // specify what fields to map to what views String[] from = { PapyrusContentProvider.Libraries.FIELD_NAME }; int[] to = { android.R.id.text1 }; libraries = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, null, from, to); libraries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(libraries); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(BOOKS, null, this); getLoaderManager().initLoader(LIBRARIES, null, this); }
From source file:ca.ualberta.slevinsk.gameshow.BuzzerStatsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final List<String> test = new ArrayList<>(); final ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.list_item, test); setListAdapter(adapter);/*from w w w. j a v a2 s .c o m*/ final Spinner spinner = (Spinner) getView().findViewById(R.id.spinner); ArrayList<SpecialPair<String, Integer>> choices = new ArrayList<>(); choices.add(new SpecialPair<String, Integer>("2 Player Mode", 2)); choices.add(new SpecialPair<String, Integer>("3 Player Mode", 3)); choices.add(new SpecialPair<String, Integer>("4 Player Mode", 4)); ArrayAdapter<SpecialPair<String, Integer>> adapter2 = new ArrayAdapter<>(getContext(), R.layout.list_item, choices); Generator<List, Integer> dataGenerator = new Generator<List, Integer>() { @Override public List generate(Integer arg) { return BuzzerCounterController.generateStatsData(arg); } }; SpinListener listener = new SpinListener(spinner, test, adapter, dataGenerator); spinner.setAdapter(adapter2); spinner.setOnItemSelectedListener(listener); BuzzerCounterController.getBuzzerCounterContainer().addListener(listener); }
From source file:com.adithya321.sharesanalysis.fragments.SharePurchaseFragment.java
@Nullable @Override/*from w ww . jav a 2 s.c o m*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false); databaseHandler = new DatabaseHandler(getContext()); sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view); emptyTV = (TextView) root.findViewById(R.id.empty); arrow = (ImageView) root.findViewById(R.id.arrow); setRecyclerViewAdapter(); FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab); addPurchaseFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Add Share Purchase"); dialog.setContentView(R.layout.dialog_add_share_purchase); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name); List<String> nseList = ShareUtils.getNseList(getContext()); FilterWithSpaceAdapter<String> arrayAdapter = new FilterWithSpaceAdapter<>(getContext(), android.R.layout.simple_dropdown_item_1line, nseList); name.setThreshold(1); name.setAdapter(arrayAdapter); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); for (Share share : sharesList) { shares.add(share.getName()); } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new); RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing); if (shares.size() == 0) existingRB.setVisibility(View.GONE); (newRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE); } }); (existingRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); Calendar calendar = Calendar.getInstance(); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start, month_start - 1, day_start); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { selectDate.setText(new StringBuilder().append(day_start).append("/") .append(month_start).append("/").append(year_start)); } }); dialog.show(); } }); Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn); addPurchaseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Share share = new Share(); share.setId(databaseHandler.getNextKey("share")); share.setPurchases(new RealmList<Purchase>()); Purchase purchase = new Purchase(); purchase.setId(databaseHandler.getNextKey("purchase")); if (newRB.isChecked()) { String sName = name.getText().toString().trim(); if (sName.equals("")) { Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show(); return; } else { share.setName(sName); purchase.setName(sName); } } String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); share.setDateOfInitialPurchase(date); purchase.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); try { purchase.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } EditText price = (EditText) dialog.findViewById(R.id.buying_price); try { purchase.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } purchase.setType("buy"); if (newRB.isChecked()) { if (!databaseHandler.addShare(share, purchase)) { Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show(); return; } } else { purchase.setName(spinner.getSelectedItem().toString()); databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase); } setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); return root; }