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.appnexus.opensdkapp.SettingsFragment.java
private static Spinner initDropdown(View out, ViewGroup container, int resId, int stringsId) { Spinner dropdown = (Spinner) out.findViewById(resId); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(container.getContext(), stringsId, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dropdown.setAdapter(adapter);//from w w w .j ava 2 s . c o m return dropdown; }
From source file:org.thomasamsler.android.flashcards.fragment.SetupFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mIsSpinnerReady = false;/*from ww w .j av a2 s. c o m*/ mPreferences = getActivity().getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); mPreferenceUserName = mPreferences.getString(PREFERENCE_FCEX_USER_NAME, ""); mProgressBar = (ProgressBar) getActivity().findViewById(R.id.progressBar); mEditTextUserName = (EditText) getActivity().findViewById(R.id.editTextSetupUserName); mEditTextUserName.setText(mPreferenceUserName); ImageButton imageButtonSave = (ImageButton) getActivity().findViewById(R.id.imageButtonSetupSave); imageButtonSave.setOnClickListener(new OnClickListener() { public void onClick(View v) { mProgressBar.setVisibility(ProgressBar.VISIBLE); String userName = mEditTextUserName.getText().toString(); if (null != userName && !"".equals(userName) && !mPreferenceUserName.equals(userName)) { if (hasConnectivity()) { new GetExternalCardSetsTask().execute(userName); } else { mProgressBar.setVisibility(ProgressBar.GONE); Toast.makeText(getActivity().getApplicationContext(), R.string.util_connectivity_error, Toast.LENGTH_SHORT).show(); } } else { mProgressBar.setVisibility(ProgressBar.GONE); } } }); ImageButton imageButtonCancel = (ImageButton) getActivity().findViewById(R.id.imageButtonSetupCancel); imageButtonCancel.setOnClickListener(new OnClickListener() { public void onClick(View v) { ((MainApplication) getActivity().getApplication()).doAction(ACTION_SHOW_CARD_SETS, Boolean.TRUE); } }); mCheckBoxShowSample = (CheckBox) getActivity().findViewById(R.id.checkBoxSetupShowSample); mCheckBoxShowSample.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(PREFERENCE_SHOW_SAMPLE, isChecked); editor.commit(); } }); mPreferenceShowSample = mPreferences.getBoolean(PREFERENCE_SHOW_SAMPLE, PREFERENCE_SHOW_SAMPLE_DEFAULT); mCheckBoxShowSample.setChecked(mPreferenceShowSample); mPreferenceFontSize = mPreferences.getInt(PREFERENCE_FONT_SIZE, PREFERENCE_NORMAL_FONT_SIZE); mSpinner = (Spinner) getActivity().findViewById(R.id.spinnerFontSize); mSpinnerAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.font_size_array, android.R.layout.simple_spinner_item); mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinner.setAdapter(mSpinnerAdapter); mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { SharedPreferences.Editor editor = mPreferences.edit(); editor.putInt(PREFERENCE_FONT_SIZE, pos); editor.commit(); // We don't want to show the message when the spinner is initialize via setSelection() below. if (mIsSpinnerReady && mSpinnerPosition != pos) { Toast.makeText(getActivity().getApplicationContext(), R.string.setup_changed_font_size, Toast.LENGTH_SHORT).show(); } else { mIsSpinnerReady = true; } ((MainApplication) getActivity().getApplication()).doAction(ACTION_FONT_SIZE_CHANGE, Integer.valueOf(pos)); mSpinnerPosition = pos; } public void onNothingSelected(AdapterView<?> arg0) { /* Nothing to do */} }); switch (mPreferenceFontSize) { case PREFERENCE_SMALL_FONT_SIZE: mSpinner.setSelection(PREFERENCE_SMALL_FONT_SIZE); break; case PREFERENCE_NORMAL_FONT_SIZE: mSpinner.setSelection(PREFERENCE_NORMAL_FONT_SIZE); break; case PREFERENCE_LARGE_FONT_SIZE: mSpinner.setSelection(PREFERENCE_LARGE_FONT_SIZE); break; } }
From source file:com.gmail.taneza.ronald.carbs.main.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Log.i("Carbs", this.getClass().getSimpleName() + " onCreate"); // Restore preferences SharedPreferences prefs = getPreferences(0); mLanguage = Language.values()[prefs.getInt(PREF_LANGUAGE, Language.ENGLISH.ordinal())]; mFoodItemsList = FoodItemListSerializer.getListFromString(prefs.getString(PREF_FOOD_ITEMS_LIST, "")); mRecentFoodsList = FoodItemListSerializer.getListFromString(prefs.getString(PREF_RECENT_FOODS_LIST, "")); mFoodDbAdapter = ((CarbsApp) getApplication()).getFoodDbAdapter(); mFoodDbAdapter.setLanguage(mLanguage); pruneRecentAndFoodLists();//from w w w. ja va 2 s . com setContentView(R.layout.activity_main); mSearchEditText = (ClearableEditText) findViewById(R.id.search_text); mSearchEditTextOrigLayoutParams = (LinearLayout.LayoutParams) mSearchEditText.getLayoutParams(); mSearchEditTextFullWidthLayoutParams = new LinearLayout.LayoutParams(mSearchEditTextOrigLayoutParams); mSearchEditTextFullWidthLayoutParams.weight = 1.0f; mSearchOptionSpinner = (Spinner) findViewById(R.id.search_option_spinner); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(this, R.array.search_options_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 mSearchOptionSpinner.setAdapter(arrayAdapter); mSearchOptionSpinner.setSelection(prefs.getInt(PREF_SEARCH_OPTION, FoodsFragment.SEARCH_ALL_FOODS)); mPagerAdapter = new MainPagerAdapter(getSupportFragmentManager()); mViewPager = (CustomViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(this); mActionBar = getSupportActionBar(); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); addActionBarTabs(); mViewPager.setCurrentItem(FOODS_TAB_INDEX); mActionBar.setHomeButtonEnabled(false); mHandler = new Handler(); refreshAllTabsAndMealTotal(); mEditFoodItemIndex = -1; }
From source file:com.tmall.ultraviewpager.sample.PagerActivity.java
private void initUI() { indicatorStyle = (Spinner) findViewById(R.id.indicator); indicatorGravityHor = (Spinner) findViewById(R.id.indicator_gravity_hor); indicatorGravityVer = (Spinner) findViewById(R.id.indicator_gravity_ver); ArrayAdapter<CharSequence> indicatorAdapter = ArrayAdapter.createFromResource(this, R.array.indicator_style, android.R.layout.simple_spinner_item); indicatorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); indicatorStyle.setAdapter(indicatorAdapter); ArrayAdapter<CharSequence> indicatorGraHorAdapter = ArrayAdapter.createFromResource(this, R.array.indicator_gravity_hor, android.R.layout.simple_spinner_item); indicatorGraHorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); indicatorGravityHor.setAdapter(indicatorGraHorAdapter); ArrayAdapter<CharSequence> indicatorGraVerAdapter = ArrayAdapter.createFromResource(this, R.array.indicator_gravity_ver, android.R.layout.simple_spinner_item); indicatorGraVerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); indicatorGravityVer.setAdapter(indicatorGraVerAdapter); indicatorStyle.setOnItemSelectedListener(this); indicatorGravityHor.setOnItemSelectedListener(this); indicatorGravityVer.setOnItemSelectedListener(this); loopCheckBox = (CheckBox) findViewById(R.id.loop); loopCheckBox.setOnCheckedChangeListener(this); autoScrollCheckBox = (CheckBox) findViewById(R.id.autoscroll); autoScrollCheckBox.setOnCheckedChangeListener(this); indicatorBuildBtn = (Button) findViewById(R.id.indicator_build); indicatorBuildBtn.setOnClickListener(this); }
From source file:co.carlosandresjimenez.android.gotit.RegistrationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_registration, container, false); ButterKnife.bind(this, rootView); mGoogleConnection = GoogleConnection.getInstance(getActivity()); String userEmail = mGoogleConnection.getAccountName(); if (userEmail != null && !userEmail.isEmpty()) mTvEmail.setText(userEmail);/*from ww w . jav a2 s . com*/ else Log.e(LOG_TAG, "Cannot get user's email address"); Person person = mGoogleConnection.getCurrentPerson(); if (person != null) { if (person.hasName()) { mTvUserName.setText(person.getName().getGivenName()); mTvUserLastname.setText(person.getName().getFamilyName()); } if (person.hasBirthday()) mTvUserBirthdate.setText(person.getBirthday()); if (person.hasImage()) mUserAvatarUrl = person.getImage().getUrl(); } AppCompatActivity activity = (AppCompatActivity) getActivity(); if (null != mToolbar) { activity.setSupportActionBar(mToolbar); ActionBar actionBar = activity.getSupportActionBar(); actionBar.setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp); //activity.getSupportActionBar().setIcon(R.drawable.ic_clear_white_24dp); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); } // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.user_types_labels, R.layout.spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); // Apply the adapter to the spinner mSpUserType.setAdapter(adapter); return rootView; }
From source file:com.oscarsalguero.popularmovies.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); try {/*from w ww . j av a2 s .co m*/ Context supportActionBarThemedContext = getSupportActionBar().getThemedContext(); MenuItem menuItem = menu.findItem(R.id.action_sort); SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(supportActionBarThemedContext, R.array.sort_options, R.layout.spinner_dropdown_item); AppCompatSpinner sortOptionsSpinner = new AppCompatSpinner(supportActionBarThemedContext); sortOptionsSpinner.setAdapter(spinnerAdapter); sortOptionsSpinner.setOnItemSelectedListener(onItemSelectedListener); MenuItemCompat.setActionView(menuItem, sortOptionsSpinner); } catch (Exception e) { Log.d(LOG_TAG, "An error has occurred creating sort order dropdown menu in action bar", e); } return true; }
From source file:net.tacks_a.ankicard.fragment.ExamCondFragment.java
private void setSortToAdapter() { LogUtil.logDebug();//from ww w . ja va 2 s . c om // Spinner? ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.ary_sort_type, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpnSortType.setAdapter(adapter); // ?? for (int i = 0; i < adapter.getCount(); i++) { if (mExamCond.getSortType() == i) { mSpnSortType.setSelection(i); } } }
From source file:eu.vranckaert.worktime.utils.donations.DonationsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /* Flattr *//*w ww. j ava 2 s.c om*/ if (DonationsUtils.getResourceBoolean(getActivity(), "donations__flattr_enabled")) { // inflate flattr view into stub ViewStub flattrViewStub = (ViewStub) getActivity().findViewById(R.id.donations__flattr_stub); flattrViewStub.inflate(); buildFlattrView(); } /* Google */ mGoogleEnabled = DonationsUtils.getResourceBoolean(getActivity(), "donations__google_enabled"); if (mGoogleEnabled) { // inflate google view into stub ViewStub googleViewStub = (ViewStub) getActivity().findViewById(R.id.donations__google_stub); googleViewStub.inflate(); // get catalog from xml config CATALOG = DonationsUtils.getResourceStringArray(getActivity(), "donations__google_catalog"); // choose donation amount mGoogleSpinner = (Spinner) getActivity().findViewById(R.id.donations__google_android_market_spinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.donations__google_android_market_promt_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mGoogleSpinner.setAdapter(adapter); mHandler = new Handler(); mDonatePurchaseObserver = new DonatePurchaseObserver(mHandler); mBillingService = new BillingService(); mBillingService.setContext(getActivity()); Button btGoogle = (Button) getActivity() .findViewById(R.id.donations__google_android_market_donate_button); btGoogle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { donateGoogleOnClick(v); } }); } /* PayPal */ if (DonationsUtils.getResourceBoolean(getActivity(), "donations__paypal_enabled")) { // inflate paypal view into stub ViewStub paypalViewStub = (ViewStub) getActivity().findViewById(R.id.donations__paypal_stub); paypalViewStub.inflate(); Button btPayPal = (Button) getActivity().findViewById(R.id.donations__paypal_donate_button); btPayPal.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { donatePayPalOnClick(v); } }); } }
From source file:com.armtimes.dialogs.DialogSettings.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View settingsView = getActivity().getLayoutInflater().inflate(R.layout.dialog_settings, null); // Initialize and set Storage Spinner adapter. Spinner storageSpinner = (Spinner) settingsView.findViewById(R.id.spinnerImageStorage); ArrayAdapter storageAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.image_storage_array, android.R.layout.simple_spinner_item); storageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); storageSpinner.setAdapter(storageAdapter); storageSpinner.setSelection(getImageStorage(getActivity())); storageSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*from www. j av a 2 s .c o m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { setImageStorage(position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); // Initialize and set Saved news number Spinner Adapter Spinner savedNewsSpinner = (Spinner) settingsView.findViewById(R.id.spinnerStoredArticlesCount); ArrayAdapter savedNewsAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.saved_articles_number_array, android.R.layout.simple_spinner_item); savedNewsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); savedNewsSpinner.setAdapter(savedNewsAdapter); int pos = savedNewsAdapter.getPosition(Integer.toString(getAllowedNewsCount(getActivity()))); savedNewsSpinner.setSelection(pos); savedNewsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { final String value = (String) parent.getItemAtPosition(position); setSavedNewsCount(value); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); initImageQualityControllers(settingsView); initFontSizeStuff(settingsView); // Creates About Us Alert dialog which extends from DialogFragment. return new AlertDialog.Builder(getActivity()).setTitle(R.string.settings) .setNeutralButton(R.string.about_us_close, null).setView(settingsView).create(); }