List of usage examples for android.widget Spinner setAdapter
@Override public void setAdapter(SpinnerAdapter adapter)
From source file:com.z299studio.pb.DeleteCategory.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView;//from w w w . j av a2 s . c o m if (Application.getInstance() == null || Application.getInstance().getAccountManager() == null) { return null; } if (savedInstanceState != null) { mPosition = savedInstanceState.getInt("category"); } rootView = inflater.inflate(R.layout.dialog_delete_category, container); Button button = (Button) rootView.findViewById(R.id.ok); button.setOnClickListener(this); button = (Button) rootView.findViewById(R.id.cancel); button.setOnClickListener(this); Spinner spinner = (Spinner) rootView.findViewById(R.id.spinner); String[] allNames = Application.getInstance().getSortedCategoryNames(); String[] deletableNames = new String[allNames.length - 1]; int i, j = 0; for (i = 1; i < allNames.length; ++i) { deletableNames[j++] = allNames[i]; } if (mPosition < 0) { int[] allIds = Application.getInstance().getSortedCategoryIds(); for (i = 1; i < allIds.length; ++i) { if (mCategory == allIds[i]) { mPosition = i; break; } } mPosition -= 1; if (mPosition < 0) { mPosition = 0; } } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, deletableNames); spinner.setAdapter(spinnerAdapter); spinner.setSelection(mPosition); spinner.setOnItemSelectedListener(this); mCheckBox = (CheckBox) rootView.findViewById(R.id.checkbox); return rootView; }
From source file:org.elasticdroid.SshConnectorView.java
/** * Method called to populate the open ports spinner in the UI *///from www . ja v a2s . c o m private void populateSpinner() { if (openPorts == null) { return; } int selectedIndex = 0; //set selected index to index of port 22 if available. Spinner portSpinner = (Spinner) findViewById(R.id.sshConnectorPortSpinner); if (openPorts.contains("22")) { Log.d(TAG, "Found port 22 in openPorts.Setting as selected."); selectedIndex = openPorts.indexOf("22"); } //create an ArrayAdapter<String> to hold this ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, openPorts); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); portSpinner.setAdapter(spinnerAdapter); portSpinner.setSelection(selectedIndex); //0 if port 22 unavailable, else indexof(port22) }
From source file:com.adithya321.sharesanalysis.fragments.SalesShareFragment.java
private void setRecyclerViewAdapter() { sharesList = databaseHandler.getShares(); final List<Purchase> salesList = databaseHandler.getSales(); PurchaseShareAdapter purchaseAdapter = new PurchaseShareAdapter(getContext(), salesList); purchaseAdapter.setOnItemClickListener(new PurchaseShareAdapter.OnItemClickListener() { @Override//from w w w .j av a 2 s. c o m public void onItemClick(View itemView, int position) { final Purchase purchase = salesList.get(position); final Dialog dialog = new Dialog(getActivity()); dialog.setTitle("Edit Share Sale"); dialog.setContentView(R.layout.dialog_sell_share_holdings); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); int pos = 0; for (int i = 0; i < sharesList.size(); i++) { shares.add(sharesList.get(i).getName()); if (sharesList.get(i).getName().equals(purchase.getName())) pos = i; } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); spinner.setSelection(pos); spinner.setVisibility(View.VISIBLE); final EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); final EditText price = (EditText) dialog.findViewById(R.id.selling_price); quantity.setText(String.valueOf(purchase.getQuantity())); price.setText(String.valueOf(purchase.getPrice())); Calendar calendar = Calendar.getInstance(); calendar.setTime(purchase.getDate()); 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(SalesShareFragment.this); Button sellShareBtn = (Button) dialog.findViewById(R.id.sell_share_btn); sellShareBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Purchase p = new Purchase(); p.setId(purchase.getId()); String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); p.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } try { p.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } try { p.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } p.setType("sell"); p.setName(spinner.getSelectedItem().toString()); databaseHandler.updatePurchase(p); setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); salesRecyclerView.setHasFixedSize(true); salesRecyclerView.setAdapter(purchaseAdapter); salesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); }
From source file:org.peercast.pecaport.PecaPortFragmentBase.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mContentView = (ContainerFrame) view; final Spinner vWanConnectionSelector = (Spinner) mContentView.findViewById(R.id.vWanConnectionSelector); final TableView vMappingEntries = (TableView) mContentView.findViewById(R.id.vMappingEntries); vPeerCast = (PeerCastButton) mContentView.findViewById(R.id.vPeerCast); final ImageButton vAdd = (ImageButton) mContentView.findViewById(R.id.vAdd); if (!mPreferences.isDebug()) vAdd.setVisibility(View.GONE); mWanConnectionAdapter = new WanConnectionsAdapter(); vWanConnectionSelector.setAdapter(mWanConnectionAdapter); final AdapterView.OnItemSelectedListener wanItemListener = new AdapterView.OnItemSelectedListener() { @Override//from w w w. java2s . c om public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { WanConnection conn = (WanConnection) parent.getItemAtPosition(position); String externalIp = conn.getExternalIp(); if (externalIp == null) externalIp = getContext().getString(R.string.t_empty); mViewBinder.updateTextView(R.id.vWanExternalIp, externalIp); onPreparePeerCastButton(vPeerCast, conn); mMappingAdapter.setPortMappings(conn.getMappingEntries()); updateAddButton(vAdd); } @Override public void onNothingSelected(AdapterView<?> parent) { } }; vWanConnectionSelector.setOnItemSelectedListener(wanItemListener); mWanConnectionAdapter.registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { int enabledPos = mWanConnectionAdapter.getConnectedPosition(); if (enabledPos != -1) { wanItemListener.onItemSelected(vWanConnectionSelector, null, enabledPos, 0); } updateAddButton(vAdd); } }); mMappingAdapter = new MappingEntryAdapter(getContext(), new View.OnClickListener() { @Override public void onClick(View v) { onDeleteMapping((WanConnection) vWanConnectionSelector.getSelectedItem(), (PortMapping) v.getTag()); } }); vMappingEntries.setAdapter(mMappingAdapter); vPeerCast.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Log.d(TAG, "" + v); WanConnection conn = (WanConnection) vWanConnectionSelector.getSelectedItem(); if (conn != null) onClickPeerCastButton(vPeerCast, conn); else showToast("WanConnection not found."); } }); vAdd.setEnabled(mActiveNicInfo != null); vAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onRequestAddPort(mWanConnectionAdapter.getConnected()); } }); }
From source file:com.secretparty.app.PartyCreationDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View rootView = getActivity().getLayoutInflater().inflate(R.layout.party_creation_layout, null); final List<Thematic> thematics = mCallback.getThematicRepository().getAll(); final Spinner secret = (Spinner) rootView.findViewById(R.id.S_secrets); Spinner thematic = (Spinner) rootView.findViewById(R.id.S_theme); ArrayAdapter<Thematic> thematicArrayAdapter = new ArrayAdapter<Thematic>(getActivity(), android.R.layout.simple_spinner_dropdown_item, thematics); thematic.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//ww w .j a v a2 s. c om public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { List<Secret> secrets = thematics.get(position).getSecrets(); if (secrets.size() == 0) { Log.w("OMG", "secrets are 00"); } ArrayAdapter<Secret> adapter = new ArrayAdapter<Secret>(getActivity(), android.R.layout.simple_spinner_dropdown_item, secrets); thematicChosen = position; secret.setAdapter(adapter); } @Override public void onNothingSelected(AdapterView<?> adapterView) { List<Secret> secrets = new ArrayList<Secret>(); ArrayAdapter<Secret> adapter = new ArrayAdapter<Secret>(getActivity(), android.R.layout.simple_spinner_dropdown_item, secrets); thematicChosen = -1; secret.setAdapter(adapter); } }); thematic.setAdapter(thematicArrayAdapter); // Use the Builder class for convenient dialog construction AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(rootView).setTitle(R.string.party_join_dialog) .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String partyName = String .valueOf(((EditText) getDialog().findViewById(R.id.ET_party_name)).getText()); int duration = 60 * Integer.parseInt(String .valueOf(((EditText) getDialog().findViewById(R.id.ET_party_duration)).getText())); Thematic t = thematics.get(thematicChosen); Secret s = t.getSecrets().get(secretChosen); dismiss(); mCallback.onPartyCreated(t.getId(), s.getId(), partyName, duration); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dismiss(); Toast.makeText(getActivity(), R.string.party_creation_cancel, Toast.LENGTH_LONG).show(); } }); return builder.create(); }
From source file:org.catrobat.catroid.content.bricks.BroadcastWaitBrick.java
@Override public View getView(final Context context, int brickId, BaseAdapter baseAdapter) { if (animationState) { return view; }//from www. j a v a2s . c om view = View.inflate(context, R.layout.brick_broadcast_wait, null); view = getViewWithAlpha(alphaValue); setCheckboxView(R.id.brick_broadcast_wait_checkbox); final Brick brickInstance = this; checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { checked = isChecked; adapter.handleCheck(brickInstance, isChecked); } }); final Spinner broadcastSpinner = (Spinner) view.findViewById(R.id.brick_broadcast_wait_spinner); broadcastSpinner.setFocusableInTouchMode(false); broadcastSpinner.setFocusable(false); if (!(checkbox.getVisibility() == View.VISIBLE)) { broadcastSpinner.setClickable(true); broadcastSpinner.setEnabled(true); } else { broadcastSpinner.setClickable(false); broadcastSpinner.setEnabled(false); } final ArrayAdapter<String> spinnerAdapter = MessageContainer.getMessageAdapter(context); SpinnerAdapterWrapper spinnerAdapterWrapper = new SpinnerAdapterWrapper(context, broadcastSpinner, spinnerAdapter); broadcastSpinner.setAdapter(spinnerAdapterWrapper); broadcastSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { private boolean start = true; @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if (start) { start = false; return; } broadcastMessage = ((String) parent.getItemAtPosition(pos)).trim(); if (broadcastMessage == context.getString(R.string.new_broadcast_message)) { broadcastMessage = ""; } else { oldMessage = broadcastMessage; } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); setSpinnerSelection(broadcastSpinner); return view; }
From source file:org.otempo.view.StationActivity.java
/** * Called when the activity is first created. *//*from w w w. j av a2 s . c o m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.gc(); lastUpdateFormat = new SimpleDateFormat(getString(R.string.predicted_at), Locale.getDefault()); PeriodicWorkRequest updateWork = new PeriodicWorkRequest.Builder(UpdateWorker.class, updatePeriodMs(), TimeUnit.MILLISECONDS) .setConstraints(new Constraints.Builder().setRequiredNetworkType(NetworkType.UNMETERED) .setRequiresBatteryNotLow(true).build()) .build(); // Make sure there is nothing else running at this point. Not even the widget. The attention // of the user is on the activity. WorkManager.getInstance().cancelAllWork(); // Now start polling in the background WorkManager.getInstance().enqueueUniquePeriodicWork("SyncStations", ExistingPeriodicWorkPolicy.KEEP, updateWork); setContentView(R.layout.main); if (_favoritesDB == null) { _favoritesDB = new FavoritesDB(getApplicationContext()); } Spinner stationSpinner = findViewById(R.id.stationSpinner); _stationAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item); initStationManager(); fillStationAdapter(); _stationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); stationSpinner.setAdapter(_stationAdapter); if (_stationManager.getStation() != null) { stationSpinner.setSelection(_stationAdapter.getPosition(_stationManager.getStation())); } stationSpinner.setOnItemSelectedListener(new OnStationSelectedListener()); PreferenceManager.getDefaultSharedPreferences(getBaseContext()) .registerOnSharedPreferenceChangeListener(this); reloadPreferences(); final Button predictionHelpButton = findViewById(R.id.predictionHelpButton); if (predictionHelpButton != null) { // en landscape no hay predictionHelpButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { showDialog(DIALOG_PREDICTION_EXPLAIN_ID); // Marcando la preferencia SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); Editor editor = prefs.edit(); editor.putBoolean(Preferences.PREF_PREDICTED_TIME_WHY_CLICKED, true); editor.commit(); } }); } final Button hamburgerButton = findViewById(R.id.hamburgerButton); final DrawerLayout drawerLayout = findViewById(R.id.drawerLayout); final ListView sideMenu = findViewById(R.id.sideMenu); if (hamburgerButton != null && drawerLayout != null && sideMenu != null) { hamburgerButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { drawerLayout.openDrawer(sideMenu); } }); fillSideMenu(sideMenu, drawerLayout); } }
From source file:org.sufficientlysecure.ical.ui.MainActivity.java
private <E> void setupSpinner(final Spinner spinner, final List<E> list, final Button button) { final int id = android.R.layout.simple_spinner_item; final int dropId = android.R.layout.simple_spinner_dropdown_item; final Context ctx = this; runOnUiThread(new Runnable() { public void run() { ArrayAdapter<E> adaptor = new ArrayAdapter<>(ctx, id, list); adaptor.setDropDownViewResource(dropId); spinner.setAdapter(adaptor); if (list.size() != 0) spinner.setVisibility(View.VISIBLE); button.setVisibility(View.VISIBLE); }//from w ww. j av a 2 s .c om }); }
From source file:no.barentswatch.fiskinfo.MapActivity.java
/** * //w w w. j av a 2 s . co m * @param activityContext * The context of the current activity */ @SuppressLint("InflateParams") public void setProximityAlertDialog(Context activityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_scheduled_task_executor, null); final AlertDialog builder = new AlertDialog.Builder(activityContext).create(); builder.setTitle(R.string.map_set_proximity_alert_title); builder.setView(view); final EditText distanceEditText = (EditText) view.findViewById(R.id.scheduledProximityRangeEditText); final SeekBar seekbar = (SeekBar) view.findViewById(R.id.scheduledSetProximityRangeSeekBar); distanceEditText.setText(String.valueOf(minLenghtMeters)); final Spinner measuringUnitSpinner = (Spinner) view.findViewById(R.id.scheduledMeasuringUnitsSpinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.measurement_units, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); measuringUnitSpinner.setAdapter(adapter); seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser == true) { if (currentlySelected == meterIndex) { distanceEditText .setText(String.valueOf((int) (minLenghtMeters + (stepSizeMeters * progress)))); } else if (currentlySelected == nauticalMileIndex) { distanceEditText.setText( String.valueOf(minLenghtNauticalMiles + (stepSizeNauticalMiles * progress))); } } } }); measuringUnitSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { double distance = (distanceEditText.length() != 0 ? Double.parseDouble(distanceEditText.getText().toString()) : 0); System.out.println("posistion: " + position); System.out.println("currentlySelected: " + position); if (position == meterIndex) { if (position != currentlySelected) { distance = convertDistance(distance, position); distanceEditText.setText(String.valueOf(distance)); currentlySelected = position; } } else if (position == nauticalMileIndex) { if (position != currentlySelected) { distance = convertDistance(distance, position); distanceEditText.setText(String.valueOf(distance)); currentlySelected = position; } } else { return; } System.out.println("distance: " + distance); int newProgress = findProgress(distance, position); seekbar.setProgress(newProgress); System.out.println("progress: " + newProgress); distanceEditText.setText(String.valueOf(distance)); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); Button setProximityAlertButton = (Button) view.findViewById(R.id.scheduledSetProximityCheckerDialogButton); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); builder.setView(view); builder.setCanceledOnTouchOutside(false); setProximityAlertButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (!alarmSet) { mGpsLocationTracker = new GpsLocationTracker(getContext()); double latitude, longitude = 0; if (mGpsLocationTracker.canGetLocation()) { latitude = mGpsLocationTracker.getLatitude(); cachedLat = latitude; longitude = mGpsLocationTracker.getLongitude(); cachedLon = longitude; } else { mGpsLocationTracker.showSettingsAlert(); return; } String distance = distanceEditText.getText().toString(); cachedDistance = distance; cacheWriter = new DownloadMapLayerFromBarentswatchApiInBackground().execute("fishingfacility", "OLEX", "cachedResults", String.valueOf(longitude), String.valueOf(latitude), distance, "true"); alarmSet = true; runScheduledAlarm(); } builder.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { builder.cancel(); } }); builder.show(); }
From source file:demo.camera.library.ui.CameraCaptureActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.activity_camera_capture); CameraUtils.clearSessionConfig();/*from w ww. j a v a 2 s. c o m*/ CameraUtils.clearSessionFolders(this, true, true); Spinner spinner = (Spinner) findViewById(R.id.filterSpinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.cameraFilterNames, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner. spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); // Define a handler that receives camera-control messages from other threads. All calls // to Camera must be made on the same thread. Note we create this before the renderer // thread, so we know the fully-constructed object will be visible. mSessionConfig = CameraUtils.getSessionConfig(this); CameraUtils.clearSessionConfig(); mCameraHandler = new CameraHandler(this); mVideoEncoder = new TextureMovieEncoder(); mRecordingEnabled = mVideoEncoder.isRecording(); try { mMicEncoder = new MicrophoneEncoder(mSessionConfig); } catch (IOException e) { e.printStackTrace(); } // Configure the GLSurfaceView. This will start the Renderer thread, with an // appropriate EGL context. mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView); mGLView.setEGLContextClientVersion(2); // select GLES 2.0 mRenderer = new CameraSurfaceRenderer(mCameraHandler, mSessionConfig, mVideoEncoder); mGLView.setRenderer(mRenderer); mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mCameraManager = new AppCameraManager(this, mSessionConfig); setUpUi(); Log.d(TAG, "onCreate complete: " + this); }