List of usage examples for android.widget AdapterView getItemAtPosition
public Object getItemAtPosition(int position)
From source file:com.cmput301w17t07.moody.EditMoodActivity.java
/** * display the attributes of the mood that was selected to view <br> * Spinner dropdown logic taken from <br> * link: http://stackoverflow.com/questions/13377361/how-to-create-a-drop-down-list <br> * Author: Nicolas Tyler, 2013/07/15 8:47 <br> * taken by Xin Huang 2017-03-04 15:30 (used and swith function written by Nick 2017/03/12 14:30) <br> */// w w w. j ava 2s. c om private void displayAttributes() { final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation); if (address == null) { deleteLocation.setVisibility(View.INVISIBLE); deleteLocation.setEnabled(false); } Spinner dropdown = (Spinner) findViewById(R.id.editEmotion); String[] items = new String[] { "anger", "confusion", "disgust", "fear", "happiness", "sadness", "shame", "surprise" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items); dropdown.setAdapter(adapter); switch (editMood.getFeeling()) { case "anger": dropdown.setSelection(0); break; case "confusion": dropdown.setSelection(1); break; case "disgust": dropdown.setSelection(2); break; case "fear": dropdown.setSelection(3); break; case "happiness": dropdown.setSelection(4); break; case "sadness": dropdown.setSelection(5); break; case "shame": dropdown.setSelection(6); break; case "surprise": dropdown.setSelection(7); break; } dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { EmotionText = parent.getItemAtPosition(position).toString(); editMood.setFeeling(EmotionText); TextView sizeView = (TextView) findViewById(R.id.editSocialText); sizeView.setText("Feeling " + EmotionText + " " + SocialSituation); } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText(EditMoodActivity.this, "Please pick a feeling!", Toast.LENGTH_SHORT).show(); } }); Spinner dropdown_SocialSituation = (Spinner) findViewById(R.id.editSocialSituation); String[] item_SocialSituation = new String[] { "", "alone", "with one other person", "with two people", "with several people", "with a crowd" }; ArrayAdapter<String> adapter_SocialSituation = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, item_SocialSituation); dropdown_SocialSituation.setAdapter(adapter_SocialSituation); switch (editMood.getSocialSituation()) { case "alone": dropdown_SocialSituation.setSelection(1); break; case "with one other person": dropdown_SocialSituation.setSelection(2); break; case "with two people": dropdown_SocialSituation.setSelection(3); break; case "with several people": dropdown_SocialSituation.setSelection(4); break; case "with a crowd": dropdown_SocialSituation.setSelection(5); break; } dropdown_SocialSituation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SocialSituation = parent.getItemAtPosition(position).toString(); editMood.setSocialSituation(SocialSituation); TextView sizeView = (TextView) findViewById(R.id.editSocialText); sizeView.setText("Feeling " + EmotionText + " " + SocialSituation); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); Description = (EditText) findViewById(R.id.editDescription); Description.setText(editMood.getMoodMessage()); editBitmapImage = editMood.decodeImage(); if (editBitmapImage != null) { image.setImageBitmap(editBitmapImage); } else { image.setImageBitmap(bitmapImage); } }
From source file:com.google.android.apps.flexbox.MainActivity.java
private void initializeFlexDirectionSpinner(Menu navigationMenu) { initializeSpinner(mFlexboxLayout.getFlexDirection(), R.id.menu_item_flex_direction, navigationMenu, R.array.array_flex_direction, new AdapterView.OnItemSelectedListener() { @Override/* ww w . j ava 2 s . c o m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int flexDirection = FlexboxLayout.FLEX_DIRECTION_ROW; String selected = parent.getItemAtPosition(position).toString(); if (selected.equals(ROW)) { flexDirection = FlexboxLayout.FLEX_DIRECTION_ROW; } else if (selected.equals(ROW_REVERSE)) { flexDirection = FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE; } else if (selected.equals(COLUMN)) { flexDirection = FlexboxLayout.FLEX_DIRECTION_COLUMN; } else if (selected.equals(COLUMN_REVERSE)) { flexDirection = FlexboxLayout.FLEX_DIRECTION_COLUMN_REVERSE; } mFlexboxLayout.setFlexDirection(flexDirection); } @Override public void onNothingSelected(AdapterView<?> parent) { // No op } }, new ValueToStringConverter() { @Override public String asString(int value) { switch (value) { case FlexboxLayout.FLEX_DIRECTION_ROW: return ROW; case FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE: return ROW_REVERSE; case FlexboxLayout.FLEX_DIRECTION_COLUMN: return COLUMN; case FlexboxLayout.FLEX_DIRECTION_COLUMN_REVERSE: return COLUMN_REVERSE; default: return ROW; } } }); }
From source file:com.orange.datavenue.ValueFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { Log.d(TAG_NAME, "onViewCreated()"); super.onViewCreated(view, savedInstanceState); if (mValueAdapter == null) { mValueAdapter = new ValueAdapter(getActivity(), R.layout.value_item, R.id.name, mValues); setListAdapter(mValueAdapter);// w ww . j ava2s . com getValues(mPageNumber, true); } getListView().setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int position = firstVisibleItem + visibleItemCount; int limit = totalItemCount; mPosition = firstVisibleItem; if (position >= limit && totalItemCount > 0 && !mIsLoading) { if (mHasMorePage) { Log.d(TAG_NAME, "load next page"); mPageNumber++; mIsLoading = true; getValues(mPageNumber, false); // Append to the list when we scroll throw pages } } } }); getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Model.instance.currentValue = (Value) parent.getItemAtPosition(position); mSelected = position; getListView().setItemChecked(mSelected, true); mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(mActionModeCallback); return true; } }); }
From source file:TIG055st2014.mailmaster.Activities.ComposeActivity.java
/** * onClick for entries in the autocomplete suggestion list. *//*from w w w . j av a2 s .co m*/ public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { Toast.makeText(parent.getContext(), getApplicationContext().getResources().getString(R.string.toast_emailsel) + " " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show(); }
From source file:tinygsn.gui.android.ActivityViewData.java
public void loadVSList() { spinnerVS = (Spinner) findViewById(R.id.spinner_vs); List<String> list = new ArrayList<String>(); for (String s : vsNameList) { list.add(s);/*from w w w. ja v a 2 s. c o m*/ } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, list); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerVS.setAdapter(dataAdapter); spinnerVS.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { vsName = parent.getItemAtPosition(pos).toString(); Toast.makeText(parent.getContext(), "The virtual sensor \"" + vsName + "\" is selected.", Toast.LENGTH_SHORT).show(); controller.loadListFields(parent.getItemAtPosition(pos).toString()); } @Override public void onNothingSelected(AdapterView<?> arg0) { Toast.makeText(context, "Please select a virtual sensor", Toast.LENGTH_SHORT).show(); } }); }
From source file:com.google.android.apps.flexbox.MainActivity.java
private void initializeAlignItemsSpinner(Menu navigationMenu) { initializeSpinner(mFlexboxLayout.getAlignItems(), R.id.menu_item_align_items, navigationMenu, R.array.array_align_items, new AdapterView.OnItemSelectedListener() { @Override/*from w w w. j av a 2 s . c o m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int alignItems = FlexboxLayout.ALIGN_ITEMS_STRETCH; String selected = parent.getItemAtPosition(position).toString(); if (selected.equals(FLEX_START)) { alignItems = FlexboxLayout.ALIGN_ITEMS_FLEX_START; } else if (selected.equals(FLEX_END)) { alignItems = FlexboxLayout.ALIGN_ITEMS_FLEX_END; } else if (selected.equals(CENTER)) { alignItems = FlexboxLayout.ALIGN_ITEMS_CENTER; } else if (selected.equals(BASELINE)) { alignItems = FlexboxLayout.ALIGN_ITEMS_BASELINE; } else if (selected.equals(STRETCH)) { alignItems = FlexboxLayout.ALIGN_ITEMS_STRETCH; } mFlexboxLayout.setAlignItems(alignItems); } @Override public void onNothingSelected(AdapterView<?> parent) { // No op } }, new ValueToStringConverter() { @Override public String asString(int value) { switch (value) { case FlexboxLayout.ALIGN_ITEMS_FLEX_START: return FLEX_START; case FlexboxLayout.ALIGN_ITEMS_FLEX_END: return FLEX_END; case FlexboxLayout.ALIGN_ITEMS_CENTER: return CENTER; case FlexboxLayout.ALIGN_ITEMS_BASELINE: return BASELINE; case FlexboxLayout.ALIGN_ITEMS_STRETCH: return STRETCH; default: return STRETCH; } } }); }
From source file:com.docd.purefm.ui.fragments.BrowserFragment.java
private void initList(@NonNull final LayoutInflater inflater, @NonNull final View parent) { final AbstractBrowserActivity context = getBrowserActivity(); if (mListView != null) { final View emptyView = mListView.getEmptyView(); if (emptyView != null) { emptyView.setVisibility(View.GONE); }/*from ww w.java2 s. c om*/ mListView.setVisibility(View.GONE); } final Settings settings = Settings.getInstance(context); final ViewGroup listContainer = (ViewGroup) parent.findViewById(R.id.list_container); if (listContainer == null) { throw new RuntimeException("parent should contain ViewGroup with id R.id.list_container"); } final View swipeRefreshList; switch (settings.getListAppearance()) { case LIST: swipeRefreshList = inflater.inflate(R.layout.browser_listview, listContainer); break; case GRID: swipeRefreshList = inflater.inflate(R.layout.browser_gridview, listContainer); break; default: throw new IllegalArgumentException("Unexpected ListAppearance: " + settings.getListAppearance()); } if (swipeRefreshList == null) { throw new RuntimeException("Inflated View is null"); } mMainProgress = parent.findViewById(android.R.id.progress); mSwipeRefreshLayoutList = (SwipeRefreshLayout) swipeRefreshList .findViewById(R.id.browser_list_swipe_refresh); mSwipeRefreshLayoutEmpty = (SwipeRefreshLayout) parent.findViewById(android.R.id.empty); mListView = (AbsListView) mSwipeRefreshLayoutList.getChildAt(0); if (mListView instanceof ListView) { mAdapter = new BrowserListAdapter(context); } else { mAdapter = new BrowserGridAdapter(context); } menuController.setBrowserAdapter(this.mAdapter); mListView.setEmptyView(parent.findViewById(android.R.id.empty)); mListView.setAdapter(this.mAdapter); final View emptyView = mListView.getEmptyView(); if (emptyView != null) { emptyView.setVisibility(View.GONE); } mListView.setVisibility(View.GONE); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> av, View v, int pos, long id) { final GenericFile target = (GenericFile) (av.getItemAtPosition(pos)); if (target == null) { throw new RuntimeException("onItemClick(): item at position is null"); } if (target.isDirectory()) { mBrowser.navigate(target, true); } else { final AbstractBrowserActivity activity = getBrowserActivity(); if (activity.getGetContentMimeType() == null) { PFMFileUtils.openFileInExternalApp(activity, target.toFile()); } else { final Intent intent = new Intent(); intent.setData(getResultUriForFileFromIntent(activity.getContentResolver(), target.toFile(), activity.getIntent())); activity.setResult(Activity.RESULT_OK, intent); activity.finish(); } } } /* * Copyright (C) 2013 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ private Uri getResultUriForFileFromIntent(ContentResolver cr, File src, Intent intent) { // Try to find the preferred uri scheme Uri result = MediaHelper.fileToContentUri(cr, src); if (result == null) { result = Uri.fromFile(src); } if (Intent.ACTION_PICK.equals(intent.getAction()) && intent.getData() != null) { final String scheme = intent.getData().getScheme(); if (scheme != null) { result = result.buildUpon().scheme(scheme).build(); } } return result; } }); mListView.setChoiceMode(context.getGetContentMimeType() == null ? AbsListView.CHOICE_MODE_MULTIPLE_MODAL : AbsListView.CHOICE_MODE_NONE); mSwipeRefreshLayoutList.setOnRefreshListener(this); mSwipeRefreshLayoutEmpty.setOnRefreshListener(this); final int color2resId = settings.getTheme() == Settings.Theme.LIGHT ? R.color.holo_light_window_background : R.color.holo_dark_window_background; mSwipeRefreshLayoutList.setColorScheme(R.color.holo_light_selected, color2resId, R.color.holo_light_selected, color2resId); mSwipeRefreshLayoutEmpty.setColorScheme(R.color.holo_light_selected, color2resId, R.color.holo_light_selected, color2resId); }
From source file:tinygsn.gui.android.ActivityViewData.java
protected void loadFieldList() { spinnerField = (Spinner) findViewById(R.id.spinner_field); List<String> list = new ArrayList<String>(); for (String s : fieldList) { list.add(s);// w ww. j a v a2 s .c o m } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, list); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerField.setAdapter(dataAdapter); spinnerField.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { fieldName = parent.getItemAtPosition(pos).toString(); Toast.makeText(parent.getContext(), "The field \"" + fieldName + "\" is selected.", Toast.LENGTH_SHORT).show(); loadData(); } @Override public void onNothingSelected(AdapterView<?> arg0) { Toast.makeText(context, "Please select a field", Toast.LENGTH_SHORT).show(); } }); }
From source file:de.ub0r.android.smsdroid.ConversationListActivity.java
/** * {@inheritDoc}// w w w . j a va2 s . c o m */ public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { final Conversation c = Conversation.getConversation(this, (Cursor) parent.getItemAtPosition(position), false); final Uri target = c.getUri(); final Intent i = new Intent(this, MessageListActivity.class); i.setData(target); try { this.startActivity(i); } catch (ActivityNotFoundException e) { Log.e(TAG, "error launching intent: " + i.getAction() + ", " + i.getData()); Toast.makeText(this, "error launching messaging app!\n" + "Please contact the developer.", Toast.LENGTH_LONG).show(); } }
From source file:com.google.android.apps.flexbox.MainActivity.java
private void initializeAlignContentSpinner(Menu navigationMenu) { initializeSpinner(mFlexboxLayout.getAlignContent(), R.id.menu_item_align_content, navigationMenu, R.array.array_align_content, new AdapterView.OnItemSelectedListener() { @Override//w ww . j a va2s .c o m public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int alignContent = FlexboxLayout.ALIGN_CONTENT_STRETCH; String selected = parent.getItemAtPosition(position).toString(); if (selected.equals(FLEX_START)) { alignContent = FlexboxLayout.ALIGN_CONTENT_FLEX_START; } else if (selected.equals(FLEX_END)) { alignContent = FlexboxLayout.ALIGN_CONTENT_FLEX_END; } else if (selected.equals(CENTER)) { alignContent = FlexboxLayout.ALIGN_CONTENT_CENTER; } else if (selected.equals(SPACE_BETWEEN)) { alignContent = FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN; } else if (selected.equals(SPACE_AROUND)) { alignContent = FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND; } else if (selected.equals(STRETCH)) { alignContent = FlexboxLayout.ALIGN_CONTENT_STRETCH; } mFlexboxLayout.setAlignContent(alignContent); } @Override public void onNothingSelected(AdapterView<?> parent) { // No op } }, new ValueToStringConverter() { @Override public String asString(int value) { switch (value) { case FlexboxLayout.ALIGN_CONTENT_FLEX_START: return FLEX_START; case FlexboxLayout.ALIGN_CONTENT_FLEX_END: return FLEX_END; case FlexboxLayout.ALIGN_CONTENT_CENTER: return CENTER; case FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN: return SPACE_BETWEEN; case FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND: return SPACE_AROUND; case FlexboxLayout.ALIGN_CONTENT_STRETCH: return STRETCH; default: return STRETCH; } } }); }