List of usage examples for android.widget SpinnerAdapter getItem
Object getItem(int position);
From source file:com.flowzr.activity.RecurActivity.java
private void editRecur(Recur recur) { editStartDate(recur.startDate);/* w w w . j a v a2 s . com*/ RecurInterval interval = recur.interval; SpinnerAdapter adapter = sInterval.getAdapter(); int count = adapter.getCount(); for (int i = 0; i < count; i++) { SpinnerItem item = (SpinnerItem) adapter.getItem(i); if (interval == RecurInterval.valueOf(item.value)) { sInterval.setSelection(i); break; } } View v = selectInterval(interval); switch (interval) { case EVERY_X_DAY: editEveryXDay(v, recur); break; case WEEKLY: editWeekly(v, recur); break; case SEMI_MONTHLY: editSemiMonthly(v, recur); break; } RecurPeriod period = recur.period; sPeriod.setSelection(period.ordinal()); v = selectPeriod(period); switch (period) { case EXACTLY_TIMES: editExactlyTimes(v, recur.periodParam); break; case STOPS_ON_DATE: editStopsOnDate(v, recur.periodParam); break; } }
From source file:net.majorkernelpanic.spydroid.ClientActivity.java
/** Fetch the current streaming configuration of the remote phone **/ private void getCurrentConfiguration() { new AsyncTask<Void, Void, String>() { @Override//from w w w .j ava 2s. c o m protected String doInBackground(Void... params) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 3000); HttpConnectionParams.setSoTimeout(httpParameters, 3000); HttpClient client = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet( "http://" + editTextIP.getText().toString() + ":8080/config.json?get"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = ""; try { response = client.execute(request, responseHandler); } catch (ConnectTimeoutException e) { Log.i(TAG, "Connection timeout ! "); onCompletion(null); } catch (Exception e) { Log.e(TAG, "Could not fetch current configuration on remote device !"); e.printStackTrace(); } return response; } @Override protected void onPostExecute(String response) { try { JSONObject object = (JSONObject) new JSONTokener(response).nextValue(); ((CheckBox) findViewById(R.id.checkbox1)).setChecked(object.getBoolean("streamVideo")); ((CheckBox) findViewById(R.id.checkbox2)).setChecked(object.getBoolean("streamAudio")); for (int spinner : new int[] { R.id.spinner1, R.id.spinner2, R.id.spinner3, R.id.spinner4, R.id.spinner5 }) { Spinner view = (Spinner) findViewById(spinner); SpinnerAdapter adapter = view.getAdapter(); for (int i = 0; i < adapter.getCount(); i++) { Iterator<String> keys = object.keys(); while (keys.hasNext()) { String key = keys.next(); if (adapter.getItem(i).equals(object.get(key))) { view.setSelection(i); } } } } generateURI(); connectToServer(); } catch (Exception e) { stopStreaming(); e.printStackTrace(); } } }.execute(); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@SuppressLint("InflateParams") private void optionTemplate() { final int userId = Util.getUserId(Process.myUid()); // Build view LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.template, null); final Spinner spTemplate = (Spinner) view.findViewById(R.id.spTemplate); Button btnRename = (Button) view.findViewById(R.id.btnRename); ExpandableListView elvTemplate = (ExpandableListView) view.findViewById(R.id.elvTemplate); // Template selector final SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item); spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0", getString(R.string.title_default)); spAdapter.add(defaultName);//from w w w . j a va 2 s .c o m for (int i = 1; i <= 4; i++) { String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i), getString(R.string.title_alternate) + " " + i); spAdapter.add(alternateName); } spTemplate.setAdapter(spAdapter); // Template definition final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, view, R.layout.templateentry); elvTemplate.setAdapter(templateAdapter); elvTemplate.setGroupIndicator(null); spTemplate.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { templateAdapter.notifyDataSetChanged(); } @Override public void onNothingSelected(AdapterView<?> arg0) { templateAdapter.notifyDataSetChanged(); } }); btnRename.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Util.hasProLicense(ActivityMain.this) == null) { // Redirect to pro page Util.viewUri(ActivityMain.this, cProUri); return; } final int templateId = spTemplate.getSelectedItemPosition(); if (templateId == AdapterView.INVALID_POSITION) return; AlertDialog.Builder dlgRename = new AlertDialog.Builder(spTemplate.getContext()); dlgRename.setTitle(R.string.title_rename); final String original = (templateId == 0 ? getString(R.string.title_default) : getString(R.string.title_alternate) + " " + templateId); dlgRename.setMessage(original); final EditText input = new EditText(spTemplate.getContext()); dlgRename.setView(input); dlgRename.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String name = input.getText().toString(); if (TextUtils.isEmpty(name)) { PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId), null); name = original; } else { PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId), name); } spAdapter.remove(spAdapter.getItem(templateId)); spAdapter.insert(name, templateId); spAdapter.notifyDataSetChanged(); } }); dlgRename.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing } }); dlgRename.create().show(); } }); // Build dialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(R.string.menu_template); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(view); alertDialogBuilder.setPositiveButton(getString(R.string.msg_done), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); // Show dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }