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:com.example.vivek.team.EditorActivity.java
/** * Setup the dropdown spinner that allows the user to select the gender of the user. *//* w w w . ja v a2s. c om*/ private void setupSpinner() { // Create adapter for spinner. The list options are from the String array it will use // the spinner will use the default layout ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options, android.R.layout.simple_spinner_item); // Specify dropdown layout style - simple list view with 1 item per line genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); // Apply the adapter to the spinner mGenderSpinner.setAdapter(genderSpinnerAdapter); // Set the integer mSelected to the constant values mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String selection = (String) parent.getItemAtPosition(position); if (!TextUtils.isEmpty(selection)) { if (selection.equals(getString(R.string.gender_male))) { mGender = GENDER_MALE; // Male } else if (selection.equals(getString(R.string.gender_female))) { mGender = GENDER_FEMALE; // Female } else { mGender = GENDER_SELECT; } } } // Because AdapterView is an abstract class, onNothingSelected must be defined @Override public void onNothingSelected(AdapterView<?> parent) { mGender = 0; // Unknown } }); }
From source file:de.teunito.android.cyclelife.RennradNewsShare.java
/** Called when the activity is first created. */ @Override/*from w w w .ja va 2 s .co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.share_rennradnews); Bundle data = new Bundle(); data = getIntent().getExtras(); trackId = data.getLong("trackId"); mTrackDb = TrackDb.getInstance(getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); APIKey = prefs.getString(Preferences.RENNRADNEWS_API_KEY, ""); bikeId = prefs.getString(Preferences.RENNRADNEWS_BIKE_ID, ""); weight = prefs.getString(Preferences.WEIGHT, ""); tv = (TextView) findViewById(R.id.rnsShareTitle); tv.setText("Share your track " + trackId + " to rennrad-news.de community!"); bt = (Button) findViewById(R.id.rnsShareBtn); etTemp = (EditText) findViewById(R.id.rnsShareTemp); spSports = (Spinner) findViewById(R.id.rnsShareSports); spZone = (Spinner) findViewById(R.id.rnsShareZone); spWeather = (Spinner) findViewById(R.id.rnsShareWeather); spMood = (Spinner) findViewById(R.id.rnsShareMood); sportsAdapter = ArrayAdapter.createFromResource(this, R.array.sports, android.R.layout.simple_spinner_item); zoneAdapter = ArrayAdapter.createFromResource(this, R.array.zone, android.R.layout.simple_spinner_item); weatherAdapter = ArrayAdapter.createFromResource(this, R.array.weather, android.R.layout.simple_spinner_item); moodAdapter = ArrayAdapter.createFromResource(this, R.array.mood, android.R.layout.simple_spinner_item); sportsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); zoneAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); weatherAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); moodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spSports.setAdapter(sportsAdapter); spZone.setAdapter(zoneAdapter); spWeather.setAdapter(weatherAdapter); spMood.setAdapter(moodAdapter); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog = ProgressDialog.show(RennradNewsShare.this, "", "Uploading. Please wait...", true); sportsID = String.valueOf(spSports.getSelectedItemPosition() + 1); zoneId = String.valueOf(spZone.getSelectedItemPosition() + 1); weatherId = String.valueOf(spWeather.getSelectedItemPosition() + 1); moodId = String.valueOf(spMood.getSelectedItemPosition() + 1); temperature = etTemp.getText().toString(); // execute is a blocking call, it's best to call this code in a thread separate from the ui's uploadThread.start(); } }); handler = new Handler() { public void handleMessage(Message msg) { String result = msg.getData().getString("result"); if (result.contains("success")) { Toast.makeText(getApplicationContext(), "Uploaded: " + result, Toast.LENGTH_LONG).show(); finish(); } else Toast.makeText(getApplicationContext(), "Error: " + result, Toast.LENGTH_LONG).show(); } }; if (APIKey.length() < 20) { AlertDialog.Builder builder = new AlertDialog.Builder(RennradNewsShare.this); builder.setMessage("Please enter first the rennrad-news.de API-key in the Settings!") .setCancelable(false).setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { RennradNewsShare.this.finish(); startActivity(new Intent(RennradNewsShare.this, Preferences.class)); } }); builder.create().show(); } }
From source file:org.thialfihar.android.apg.ui.ImportKeysActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.import_keys_activity); mImportButton = (BootstrapButton) findViewById(R.id.import_import); mImportButton.setOnClickListener(new OnClickListener() { @Override//from w w w. j av a 2s. com public void onClick(View v) { importKeys(); } }); getSupportActionBar().setDisplayShowTitleEnabled(false); setupDrawerNavigation(savedInstanceState); // set drop down navigation mNavigationStrings = getResources().getStringArray(R.array.import_action_list); Context context = getSupportActionBar().getThemedContext(); ArrayAdapter<CharSequence> navigationAdapter = ArrayAdapter.createFromResource(context, R.array.import_action_list, android.R.layout.simple_spinner_dropdown_item); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setListNavigationCallbacks(navigationAdapter, this); handleActions(savedInstanceState, getIntent()); }
From source file:net.net76.lifeiq.TaskiQ.RegisterActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); inputFirstname = (EditText) findViewById(R.id.firstname); inputSurname = (EditText) findViewById(R.id.surname); inputUserID = (EditText) findViewById(R.id.userID); inputEmail = (EditText) findViewById(R.id.email); //1 inputPassword = (EditText) findViewById(R.id.password); //1inputPassword2 = (EditText) findViewById(R.id.password2); Spinner spinner = (Spinner) findViewById(R.id.spinner); EULA = (TextView) findViewById(R.id.EULA); SpannableString content = new SpannableString(EULA.getText().toString()); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); EULA.setText(content);/* w w w . j av a 2s . co m*/ EULA.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PackageInfo versionInfo = getPackageInfo(); // EULA title String title = RegisterActivity.this.getString(R.string.app_name) + " v " + versionInfo.versionName; // EULA text String message = RegisterActivity.this.getString(R.string.eula_string); android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(RegisterActivity.this) .setTitle(title).setMessage(message).setCancelable(false) .setPositiveButton(R.string.accept, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { EULAAccept = true; // Close dialog dialogInterface.dismiss(); } }).setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { EULAAccept = false; } }); builder.create().show(); } }); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Country_array, 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 spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Log.v("item", (String) parent.getItemAtPosition(position)); countryString = (String) parent.getItemAtPosition(position); } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); btnRegister = (Button) findViewById(R.id.btnRegister); btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen); // Progress dialog pDialog = new ProgressDialog(this); //pDialog.setCancelable(false); pDialog.setCanceledOnTouchOutside(false); // Session manager session = new SessionManager(getApplicationContext()); // SQLite database handler db = new SQLiteHandler(getApplicationContext()); // Check if user is already logged in or not if (session.isLoggedIn()) { // User is already logged in. Take him to main activity Intent intent = new Intent(RegisterActivity.this, MainActivity.class); startActivity(intent); finish(); } // Register Button Click event btnRegister.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { String Firstname = inputFirstname.getText().toString(); String Surname = inputSurname.getText().toString(); String UserID = inputUserID.getText().toString(); String email = inputEmail.getText().toString(); //1 String password = inputPassword.getText().toString(); //1 String password2 = inputPassword2.getText().toString(); if (!Firstname.isEmpty() && !Surname.isEmpty() && !email.isEmpty() && !UserID.isEmpty()) { if (isEmailValid(email)) { if (!UserID.contains(" ")) { if (!countryString.equals("Select country of residence")) { if (EULAAccept.equals(true)) { if (isNetworkAvaliable(getApplicationContext())) { registerUser(Firstname, Surname, UserID, email, countryString); } else { Toast.makeText(getApplicationContext(), "Currently there is no network. Please try later.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "Please read and accept End User License Agreement.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "Please select a country of residence.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "In the User ID no spaces are allowed.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "Please enter a valid email address!", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "Please enter your details!", Toast.LENGTH_SHORT) .show(); } } }); // Link to Login Screen btnLinkToLogin.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(getApplicationContext(), LoginActivity.class); startActivity(i); finish(); } }); }
From source file:org.irmacard.cardemu.selfenrol.EnrollSelectActivity.java
/** * Called when the user presses the continue button *///w w w .ja va 2s . c o m protected void advanceScreen() { switch (screen) { case SCREEN_START: setContentView(R.layout.enroll_activity_bac); screen = SCREEN_BAC; updateProgressCounter(screen - 1); Spinner spinner = (Spinner) findViewById(R.id.bac_selector); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.document_list, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Log.v(TAG, (String) parent.getItemAtPosition(position)); RelativeLayout drivers_license = (RelativeLayout) findViewById(R.id.drivers_license_data); RelativeLayout passport = (RelativeLayout) findViewById(R.id.passport_data); if (position == 0) { drivers_license.setVisibility(View.GONE); passport.setVisibility(View.VISIBLE); next_activity = PASSPORT_ACTIVITY; } else if (position == 1) { drivers_license.setVisibility(View.VISIBLE); passport.setVisibility(View.GONE); next_activity = DL_ACTIVITY; } else { throw new IllegalArgumentException("Pulldown list provided unspecified argument"); } if (bacFieldWatcher != null) bacFieldWatcher.onTextChanged("", 0, 0, 0); } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); spinner.setSelection(settings.getInt("enroll_document", PASSPORT_ACTIVITY)); populateBacAndBapFields(); EditText docnrEditText; EditText dobEditText; EditText doeEditText; long bacDob; long bacDoe; enableContinueButton(); setBacFieldWatcher(); break; case SCREEN_BAC: if (next_activity == PASSPORT_ACTIVITY) { // Store the entered document number and dates in the settings. docnrEditText = (EditText) findViewById(R.id.doc_nr_edittext); dobEditText = (EditText) findViewById(R.id.dob_edittext); doeEditText = (EditText) findViewById(R.id.doe_edittext); if (docnrEditText != null && dobEditText != null && doeEditText != null) { bacDob = 0; bacDoe = 0; try { String dobString = dobEditText.getText().toString(); String doeString = doeEditText.getText().toString(); if (dobString.length() != 0) bacDob = hrDateFormat.parse(dobString).getTime(); if (doeString.length() != 0) bacDoe = hrDateFormat.parse(doeString).getTime(); } catch (ParseException e) { // Should not happen: the DOB and DOE EditTexts are set only by the DatePicker's, // OnDateSetListener, which should always set a properly formatted string. e.printStackTrace(); } if (bacDoe < System.currentTimeMillis()) { showErrorScreen(getString(R.string.error_enroll_passport_expired), getString(R.string.abort), 0, getString(R.string.retry), SCREEN_BAC); return; } settings.edit().putInt("enroll_document", next_activity).putLong("enroll_bac_dob", bacDob) .putLong("enroll_bac_doe", bacDoe) .putString("enroll_bac_docnr", docnrEditText.getText().toString()).apply(); } Intent i = new Intent(this, PassportEnrollActivity.class); startActivityForResult(i, PassportEnrollActivity.PassportEnrollActivityCode); } else if (next_activity == DL_ACTIVITY) { //safe the mrz text field for later. EditText mrzText = (EditText) findViewById(R.id.mrz); if (mrzText != null) { settings.edit().putInt("enroll_document", next_activity) .putString("mrz", mrzText.getText().toString()).apply(); } //TODO handle DL GUI Intent i = new Intent(this, DriversLicenseEnrollActivity.class); startActivityForResult(i, DriversLicenseEnrollActivity.DriversLicenseEnrollActivityCode); } else { throw new IllegalStateException("Enroll Activity advancing an unknown screen: " + screen); } break; case SCREEN_ISSUE: case SCREEN_ERROR: screen = SCREEN_START; finish(); break; default: Log.e(TAG, "Error, screen switch fall through: " + screen); break; } }
From source file:com.beem.project.beem.ui.wizard.CreateAccountFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.create_account, container, false); username = (EditText) v.findViewById(R.id.create_account_username); username.addTextChangedListener(mTextWatcher); password = (EditText) v.findViewById(R.id.create_account_password); password.addTextChangedListener(mTextWatcher); confirmPassword = (EditText) v.findViewById(R.id.create_account_confirm_password); confirmPassword.addTextChangedListener(mTextWatcher); errorText = (TextView) v.findViewById(R.id.error_label); mSettingsWarningLabel = (TextView) v.findViewById(R.id.settings_warn_label); createButton = (Button) v.findViewById(R.id.next); createButton.setOnClickListener(this); serverEdit = (AutoCompleteTextView) v.findViewById(R.id.xmpp_server); ArrayAdapter<CharSequence> completeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.xmpp_server_list, R.layout.simple_combobox_item); serverEdit.setAdapter(completeAdapter); serverEdit.addTextChangedListener(mTextWatcher); // show the list on second click on the text view serverEdit.setOnClickListener(new OnClickListener() { @Override// w w w .j a v a 2s . c o m public void onClick(View v) { serverEdit.showDropDown(); } }); return v; }
From source file:com.gmail.taneza.ronald.carbs.myfoods.MyFoodDetailsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_food_details); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mFoodDbAdapter = ((CarbsApp) getApplication()).getFoodDbAdapter(); // Get the message from the intent Intent intent = getIntent();//from w w w .ja v a 2 s .co m mFoodItem = intent.getParcelableExtra(MY_FOOD_ITEM_MESSAGE); FoodItemInfo foodItemInfo; Mode mode = Mode.values()[intent.getIntExtra(MY_FOOD_ACTIVITY_MODE_MESSAGE, Mode.NewFood.ordinal())]; mMode = mode; if (mode == Mode.NewFood) { foodItemInfo = new FoodItemInfo(mFoodItem, NEW_FOOD_DEFAULT_NAME, NEW_FOOD_DEFAULT_QUANTITY_PER_UNIT, NEW_FOOD_DEFAULT_CARBS, NEW_FOOD_DEFAULT_UNIT_TEXT); } else { foodItemInfo = mFoodDbAdapter.getFoodItemInfo(mFoodItem); setTitle(R.string.title_activity_my_food_edit); Button okButton = (Button) findViewById(R.id.my_food_ok_button); okButton.setText(R.string.save_food_details); } mFoodNameTextView = (TextView) findViewById(R.id.my_food_name); mFoodNameTextView.setText(foodItemInfo.getName()); // Request focus and show soft keyboard automatically mFoodNameTextView.requestFocus(); getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); mQuantityEditText = (EditText) findViewById(R.id.my_food_quantity_edit); mQuantityEditText.setText(Integer.toString(foodItemInfo.getQuantityPerUnit())); mQuantityUnitTextSpinner = (Spinner) findViewById(R.id.my_food_quantity_unit_spinner); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(this, R.array.quantity_unit_text_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mQuantityUnitTextSpinner.setAdapter(arrayAdapter); mQuantityUnitTextSpinner.setSelection(arrayAdapter.getPosition(foodItemInfo.getUnitText())); mNumCarbsTextView = (TextView) findViewById(R.id.my_food_carbs); // Display decimal place only when non-zero, so it's easier to edit String numCarbsString; float numCarbs = foodItemInfo.getNumCarbsInGrams(); if (numCarbs == (int) numCarbs) { numCarbsString = String.format(Locale.getDefault(), "%.0f", numCarbs); } else { numCarbsString = String.format(Locale.getDefault(), "%.1f", numCarbs); } mNumCarbsTextView.setText(numCarbsString); }
From source file:net.olejon.mdapp.DiseasesAndTreatmentsSearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Connected? if (!mTools.isDeviceConnected()) { mTools.showToast(getString(R.string.device_not_connected), 1); finish();/*from www . j av a 2s . c o m*/ return; } // Intent final Intent intent = getIntent(); mSearchLanguage = intent.getStringExtra("language"); final String searchString = intent.getStringExtra("string"); // Layout setContentView(R.layout.activity_diseases_and_treatments_search); // Toolbar mToolbar = (Toolbar) findViewById(R.id.diseases_and_treatments_search_toolbar); mToolbar.setTitle(getString(R.string.diseases_and_treatments_search_search) + ": \"" + searchString + "\""); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.diseases_and_treatments_search_toolbar_progressbar); mProgressBar.setVisibility(View.VISIBLE); // Spinner mSpinner = (Spinner) findViewById(R.id.diseases_and_treatments_search_spinner); ArrayAdapter<CharSequence> arrayAdapter; if (mSearchLanguage.equals("")) { arrayAdapter = ArrayAdapter.createFromResource(mContext, R.array.diseases_and_treatments_search_spinner_items_english, R.layout.activity_diseases_and_treatments_search_spinner_header); } else { arrayAdapter = ArrayAdapter.createFromResource(mContext, R.array.diseases_and_treatments_search_spinner_items_norwegian, R.layout.activity_diseases_and_treatments_search_spinner_header); } arrayAdapter.setDropDownViewResource(R.layout.activity_diseases_and_treatments_search_spinner_item); mSpinner.setAdapter(arrayAdapter); mSpinner.setOnItemSelectedListener(this); // Refresh mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById( R.id.diseases_and_treatments_search_swipe_refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.accent_blue, R.color.accent_green, R.color.accent_purple, R.color.accent_orange); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { search(mSearchLanguage, searchString, false); } }); // Recycler view mRecyclerView = (RecyclerView) findViewById(R.id.diseases_and_treatments_search_cards); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(new DiseasesAndTreatmentsSearchAdapter(mContext, new JSONArray(), "")); mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); // Search search(mSearchLanguage, searchString, true); // Correct RequestQueue requestQueue = Volley.newRequestQueue(mContext); try { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/correct/?search=" + URLEncoder.encode(searchString, "utf-8"), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { final String correctSearchString = response.getString("correct"); if (!correctSearchString.equals("")) { new MaterialDialog.Builder(mContext) .title(getString(R.string.correct_dialog_title)) .content(Html.fromHtml(getString(R.string.correct_dialog_message) + ":<br><br><b>" + correctSearchString + "</b>")) .positiveText(getString(R.string.correct_dialog_positive_button)) .negativeText(getString(R.string.correct_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { ContentValues contentValues = new ContentValues(); contentValues.put( DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING, correctSearchString); SQLiteDatabase sqLiteDatabase = new DiseasesAndTreatmentsSQLiteHelper( mContext).getWritableDatabase(); sqLiteDatabase.delete(DiseasesAndTreatmentsSQLiteHelper.TABLE, DiseasesAndTreatmentsSQLiteHelper.COLUMN_STRING + " = " + mTools.sqe(searchString) + " COLLATE NOCASE", null); sqLiteDatabase.insert(DiseasesAndTreatmentsSQLiteHelper.TABLE, null, contentValues); sqLiteDatabase.close(); mToolbar.setTitle(getString( R.string.diseases_and_treatments_search_search) + ": \"" + correctSearchString + "\""); mProgressBar.setVisibility(View.VISIBLE); search(mSearchLanguage, correctSearchString, true); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).show(); } } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("DiseasesAndTreatments", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } }
From source file:com.example.android.petsdb.EditorActivity.java
/** * Setup the dropdown spinner that allows the user to select the gender of the pet. *///w w w. java2 s .com private void setupSpinner() { // Create adapter for spinner. The list options are from the String array it will use // the spinner will use the default layout ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options, android.R.layout.simple_spinner_item); // Specify dropdown layout style - simple list view with 1 item per line genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); // Apply the adapter to the spinner mGenderSpinner.setAdapter(genderSpinnerAdapter); // Set the integer mSelected to the constant values mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String selection = (String) parent.getItemAtPosition(position); if (!TextUtils.isEmpty(selection)) { if (selection.equals(getString(R.string.gender_male))) { mGender = PetsEntry.GENDER_MALE; // Male } else if (selection.equals(getString(R.string.gender_female))) { mGender = PetsEntry.GENDER_FEMALE; // Female } else { mGender = PetsEntry.GENDER_UNKNWON; // Unknown } } } // Because AdapterView is an abstract class, onNothingSelected must be defined @Override public void onNothingSelected(AdapterView<?> parent) { mGender = 0; // Unknown } }); }
From source file:net.wespot.pim.view.InqCreateInquiryFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_new_wondermoment, container, false); wm_title = (EditText) rootView.findViewById(R.id.wonder_moment_title); wm_content = (EditText) rootView.findViewById(R.id.wonder_moment_content); wm_date = (EditText) rootView.findViewById(R.id.wonder_moment_date); wm_time = (EditText) rootView.findViewById(R.id.wonder_moment_time); // wm_location = (EditText) rootView.findViewById(R.id.wonder_moment_location); // wm_clear = (ImageView) rootView.findViewById(R.id.wonder_moment_clear); // wm_progress_bar = (ProgressBar) rootView.findViewById(R.id.wonder_moment_progress_location); wm_membership_open = (RadioButton) rootView.findViewById(R.id.wonder_moment_membership_open); wm_membership_closed = (RadioButton) rootView.findViewById(R.id.wonder_moment_membership_closed); // wm_visibility = (Spinner) rootView.findViewById(R.id.wonder_moment_visibility); wm_visibility = (Spinner) rootView.findViewById(R.id.wonder_moment_visibility); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.wonder_moment_visibility_array, R.layout.custom_spinner); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(R.layout.custom_spinner); // Apply the adapter to the spinner wm_visibility.setAdapter(adapter);// w w w . j a v a 2s .co m // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // if (!(Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1)) { // if (!(Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)){ // getActionBar().setTitle(getResources().getString(R.string.actionbar_list_data_collection_task)); // } // } // wm_save = (ImageButton) rootView.findViewById(R.id.wonder_moment_save); // wm_cancel = (ImageButton) rootView.findViewById(R.id.wonder_moment_cancel); // wm_save.setImageDrawable(getResources().getDrawable(R.drawable.ic_content_save_black)); // wm_cancel.setImageDrawable(getResources().getDrawable(R.drawable.ic_navigation_cancel_black)); // wm_save.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // save_inquiry(); // } // }); // wm_cancel.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // getActivity().onBackPressed(); // } // }); // }else { wm_membership_open.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TEMP_MEMBERSHIP = InquiryClient.OPEN_MEMBERSHIP; } }); wm_membership_closed.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TEMP_MEMBERSHIP = InquiryClient.CLOSED_MEMBERSHIP; } }); // } setDataTime(); // wm_clear.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); // intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH.toString()); // intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getResources().getString(R.string.inquiry_create_voice_recognition)); // startActivityForResult(intent, REQUEST_CODE); // } // }); // Disable button_old if no recognition service is present // PackageManager pm = getActivity().getPackageManager(); // List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); // if (activities.size() == 0) { // Toast.makeText(getActivity(), "Recognizer Not Found", 1000).show(); // } // Create inquiry new_inquiry = new InquiryLocalObject(); return rootView; }