List of usage examples for android.widget Spinner setAdapter
@Override public void setAdapter(SpinnerAdapter adapter)
From source file:com.example.mediasync3.DownloadNote.java
@Override protected void onPostExecute(Boolean result) { mDialog.dismiss();/*from w w w . j a v a 2 s.com*/ if (pos == -2) { Spinner listSpin = (Spinner) rootView.findViewById(R.id.spinner1); listSpin.setAdapter(adapterList); listSpin.setEnabled(true); } else { EditText et = (EditText) rootView.findViewById(R.id.editText1); File fl = new File(LOCAL_NOTES_DIR + "/" + fnames[pos]); et.setText(readFromFile(LOCAL_NOTES_DIR + "/" + fnames[pos])); /* ListView lv = (ListView)rootView.findViewById(R.id.listView1); ArrayList<String> dir=new ArrayList<String>(); //File sdCardRoot = Environment.getExternalStorageDirectory(); final File MusicDir = new File(LOCAL_NOTES_DIR); for (File f : MusicDir.listFiles()) { if (f.isFile()) dir.add(f.getName()); // Do your stuff } String[] localnames = dir.toArray(new String[dir.size()]); ArrayAdapter<String> ad = new ArrayAdapter<String>(mFrag.getActivity(), android.R.layout.simple_list_item_1,localnames); lv.setAdapter(ad); //TextView tv = (TextView) rootView.findViewById(R.id.textView1); //tv.setText(fnames[pos]); */ } if (result) { // Set the image now that we have it // mView.setImageDrawable(mDrawable); } else { // Couldn't download it, so show an error // showToast(mErrorMsg); } }
From source file:com.nextgis.mobile.forms.DescriptionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.setRetainInstance(true); View view = inflater.inflate(R.layout.descriptfragment, container, false); final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item); final Map<String, ArrayList<String>> mlCategories = new HashMap<String, ArrayList<String>>(); //fill spinners from xml data XmlPullParser parser = Xml.newPullParser(); try {// ww w. ja v a2s .c o m File file = new File(getActivity().getExternalFilesDir(null), "categories.xml"); if (file != null) { if (!file.exists()) { createExternalStoragePrivateFile(); file = new File(getActivity().getExternalFilesDir(null), "categories.xml"); } InputStream in = new BufferedInputStream(new FileInputStream(file)); InputStreamReader isr = new InputStreamReader(in); // auto-detect the encoding from the stream parser.setInput(isr); int eventType = parser.getEventType(); String sCatVal = null; while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_DOCUMENT: break; case XmlPullParser.START_TAG: String name = parser.getName(); if (name.equalsIgnoreCase("category")) { sCatVal = parser.getAttributeValue(null, "name"); adapter.add(sCatVal); mlCategories.put(sCatVal, new ArrayList<String>()); } else if (name.equalsIgnoreCase("subcategory")) { if (sCatVal != null) { String sSubCatVal = parser.getAttributeValue(null, "name"); mlCategories.get(sCatVal).add(sSubCatVal); } } break; } eventType = parser.next(); } if (in != null) { in.close(); } } } catch (IOException e) { // TODO } catch (Exception e) { // TODO } Spinner spinner = (Spinner) view.findViewById(R.id.spinner_cat); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { final Spinner subspinner = (Spinner) getView().findViewById(R.id.spinner_subcat); //subspinner String sCat = adapter.getItem(arg2).toString(); TextView textview = (TextView) getView().findViewById(R.id.spinner_subcat_custom); if (sCat.equalsIgnoreCase("custom")) { //enable text item textview.setEnabled(true); } else { textview.setEnabled(false); } ArrayAdapter<String> subadapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, mlCategories.get(sCat)); subadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); subspinner.setAdapter(subadapter); } public void onNothingSelected(AdapterView<?> arg0) { } }); onStoreValues(); return view; }
From source file:de.nico.ha_manager.activities.AddHomework.java
private void setSpinner() { // Set spinner with subjects Spinner subSpin = (Spinner) findViewById(R.id.spinner_subject); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, subjects); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); subSpin.setAdapter(adapter); }
From source file:com.rappsantiago.weighttracker.profile.setup.WeightHeightFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_weight_height, container, false); mTxtWeightWrapper = (TextInputLayout) view.findViewById(R.id.txt_weight_wrapper); mTxtBodyFatIndexWrapper = (TextInputLayout) view.findViewById(R.id.txt_bfi_wrapper); mTxtHeightWrapper = (TextInputLayout) view.findViewById(R.id.txt_height_wrapper); mTxtHeightInchesWrapper = (TextInputLayout) view.findViewById(R.id.txt_height_inches_wrapper); Spinner weightUnitDropdown = (Spinner) view.findViewById(R.id.dropdown_weight_unit); mWeightUnitAdapter = ArrayAdapter.createFromResource(getContext(), R.array.arr_weight_unit, android.R.layout.simple_spinner_item); weightUnitDropdown.setAdapter(mWeightUnitAdapter); weightUnitDropdown.setOnItemSelectedListener(this); Spinner heightUnitDropdown = (Spinner) view.findViewById(R.id.dropdown_height_unit); mHeightUnitAdapter = ArrayAdapter.createFromResource(getContext(), R.array.arr_height_unit, android.R.layout.simple_spinner_item); heightUnitDropdown.setAdapter(mHeightUnitAdapter); heightUnitDropdown.setOnItemSelectedListener(this); return view;//from w w w . j a v a2s. c o m }
From source file:fr.shywim.antoinedaniel.ui.fragment.VideoListFragment.java
private void setupToolbarSpinner(Spinner spinner) { spinner.setAdapter(new SpinnerAdapter() { private static final String TAG_DROPDOWN = "dropdown"; private static final String TAG_NOT_DROPDOWN = "not_dropdown"; String[] titles = getResources().getStringArray(R.array.dropdown_videos_list_titles); @Override// w ww. j a v a 2 s. c om public View getDropDownView(int position, View convertView, ViewGroup parent) { if (convertView == null || !convertView.getTag().toString().equals(TAG_NOT_DROPDOWN)) { convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.spinner_actionbar_item, parent, false); convertView.setTag(TAG_NOT_DROPDOWN); } if (position != 0) { convertView.findViewById(R.id.divider_view).setVisibility(View.GONE); } else { convertView.findViewById(R.id.divider_view).setVisibility(View.VISIBLE); } TextView tv = (TextView) convertView.findViewById(android.R.id.text1); tv.setText(getTitle(position)); return convertView; } @Override public void registerDataSetObserver(DataSetObserver observer) { } @Override public void unregisterDataSetObserver(DataSetObserver observer) { } @Override public int getCount() { return titles.length; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public boolean hasStableIds() { return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null || !convertView.getTag().toString().equals(TAG_DROPDOWN)) { convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.spinner_actionbar, parent, false); convertView.setTag(TAG_DROPDOWN); } TextView tv = (TextView) convertView.findViewById(android.R.id.text1); tv.setText(getTitle(position)); return convertView; } @Override public int getItemViewType(int position) { return 0; } @Override public int getViewTypeCount() { return 1; } @Override public boolean isEmpty() { return false; } private String getTitle(int position) { return titles[position]; } }); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { int[] colors = getResources().getIntArray(R.array.spinner_videos_color_array); int actualPosition = 0; @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Filter filter = ((CursorRecyclerAdapter) listView.getAdapter()).getFilter(); UiUtils.animateToolbarStatusBarColor(mToolbar, mStatusBarBg, colors[position], colors[actualPosition]); switch (position) { case 0: filter.filter(null); break; case 1: filter.filter("playlist_wtc"); break; case 2: filter.filter("playlist_lvn"); break; } actualPosition = position; } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:org.tomasdavid.vehicleroutingproblem.fragments.MainFragment.java
/** * {@inheritDoc}/* w w w. j a va 2 s .co m*/ */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_main, container, false); // time limit number picker initialization NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.timeLimitPicker); numberPicker.setMinValue(MIN_TIME_LIMIT); numberPicker.setMaxValue(MAX_TIME_LIMIT); numberPicker.setValue(DEFAULT_TIME_LIMIT); numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); // welcome text TextView welcomeText = (TextView) view.findViewById(R.id.welcome_text); welcomeText.setText(Html.fromHtml(getString(R.string.welcome_text))); // spinner for choosing algorithm initialization Spinner algSpinner = (Spinner) view.findViewById(R.id.algorithm_spinner); ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.algorithms, android.R.layout.simple_spinner_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); algSpinner.setAdapter(spinnerAdapter); setHasOptionsMenu(true); return view; }
From source file:am.roadpolice.roadpolice.dialogs.DialogSettings.java
private void initUpdateIntervals(final View view) { Spinner spinner = (Spinner) view.findViewById(R.id.spinnerUpdateInterval); ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.array_update_interval, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setSelection(getUpdateInterval(getActivity())); // Handle on click selected item listener. spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//from w w w.j a va 2 s . c o m public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mSelectedStateOfUpdateInterval = position; } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.heneryh.aquanotes.ui.feed.FeedActivity.java
private void fillSpinner() { Uri controllersQueryUri = Controllers.buildQueryControllersUri(); Cursor cursor = dbResolverFeedAct.query(controllersQueryUri, ControllersQuery.PROJECTION, null, null, null); startManagingCursor(cursor);//from w w w.j a v a2 s . c o m // create an array to specify which fields we want to display String[] from = new String[] { ControllersQuery.PROJECTION[ControllersQuery.TITLE] }; // create an array of the display item we want to bind our data to int[] to = new int[] { android.R.id.text1 }; // create simple cursor adapter @SuppressWarnings("deprecation") SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor, from, to); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // get reference to our spinner Spinner s = (Spinner) findViewById(R.id.ctrlr_id); s.setAdapter(adapter); }
From source file:edward.com.example.AnimationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_animation); Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar);//ww w .j a va 2 s. co m getSupportActionBar().setDisplayShowTitleEnabled(false); setViewPagerEffect(new Tablet()); Spinner spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); for (PagerType type : PagerType.values()) { spinnerAdapter.add(type.name()); } spinner.setAdapter(spinnerAdapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { setEffecft(PagerType.values()[position].name()); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:net.alchemiestick.katana.winehqappdb.filter_dialog.java
private void setupSpinner(int spId, int arrayId, String cur, AdapterView.OnItemSelectedListener listener) { Spinner sp = (Spinner) findViewById(spId); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(cx, arrayId, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp.setAdapter(adapter); int pos = adapter.getPosition(cur); sp.setSelection(pos);//from w w w. j av a2 s .com sp.setOnItemSelectedListener(listener); }