List of usage examples for android.widget AdapterView getItemAtPosition
public Object getItemAtPosition(int position)
From source file:com.google.android.apps.flexbox.FlexItemEditFragment.java
@Nullable @Override//from w w w . ja va 2s . c om public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_flex_item_edit, container, false); getDialog().setTitle(String.valueOf(mFlexItem.index + 1)); final TextInputLayout orderTextInput = (TextInputLayout) view.findViewById(R.id.input_layout_order); EditText orderEdit = (EditText) view.findViewById(R.id.edit_text_order); orderEdit.setText(String.valueOf(mFlexItem.order)); orderEdit.addTextChangedListener( new FlexEditTextWatcher(orderTextInput, new IntegerInputValidator(), R.string.must_be_integer)); final TextInputLayout flexGrowInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_grow); final EditText flexGrowEdit = (EditText) view.findViewById(R.id.edit_text_flex_grow); flexGrowEdit.setText(String.valueOf(mFlexItem.flexGrow)); flexGrowEdit.addTextChangedListener(new FlexEditTextWatcher(flexGrowInput, new NonNegativeDecimalInputValidator(), R.string.must_be_non_negative_float)); final TextInputLayout flexShrinkInput = (TextInputLayout) view.findViewById(R.id.input_layout_flex_shrink); EditText flexShrinkEdit = (EditText) view.findViewById(R.id.edit_text_flex_shrink); flexShrinkEdit.setText(String.valueOf(mFlexItem.flexShrink)); flexShrinkEdit.addTextChangedListener(new FlexEditTextWatcher(flexShrinkInput, new NonNegativeDecimalInputValidator(), R.string.must_be_non_negative_float)); final TextInputLayout flexBasisPercentInput = (TextInputLayout) view .findViewById(R.id.input_layout_flex_basis_percent); EditText flexBasisPercentEdit = (EditText) view.findViewById(R.id.edit_text_flex_basis_percent); if (mFlexItem.flexBasisPercent != FlexboxLayout.LayoutParams.FLEX_BASIS_PERCENT_DEFAULT) { flexBasisPercentEdit.setText(String.valueOf(Math.round(mFlexItem.flexBasisPercent * 100))); } else { flexBasisPercentEdit.setText(String.valueOf((int) mFlexItem.flexBasisPercent)); } flexBasisPercentEdit.addTextChangedListener(new FlexEditTextWatcher(flexBasisPercentInput, new FlexBasisPercentInputValidator(), R.string.must_be_minus_one_or_non_negative_integer)); final TextInputLayout widthInput = (TextInputLayout) view.findViewById(R.id.input_layout_width); EditText widthEdit = (EditText) view.findViewById(R.id.edit_text_width); widthEdit.setText(String.valueOf(mFlexItem.width)); widthEdit.addTextChangedListener(new FlexEditTextWatcher(widthInput, new DimensionInputValidator(), R.string.must_be_minus_one_or_minus_two_or_non_negative_integer)); final TextInputLayout heightInput = (TextInputLayout) view.findViewById(R.id.input_layout_height); EditText heightEdit = (EditText) view.findViewById(R.id.edit_text_height); heightEdit.setText(String.valueOf(mFlexItem.height)); heightEdit.addTextChangedListener(new FlexEditTextWatcher(heightInput, new DimensionInputValidator(), R.string.must_be_minus_one_or_minus_two_or_non_negative_integer)); final TextInputLayout minWidthInput = (TextInputLayout) view.findViewById(R.id.input_layout_min_width); EditText minWidthEdit = (EditText) view.findViewById(R.id.edit_text_min_width); minWidthEdit.setText(String.valueOf(mFlexItem.minWidth)); minWidthEdit.addTextChangedListener(new FlexEditTextWatcher(minWidthInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer)); final TextInputLayout minHeightInput = (TextInputLayout) view.findViewById(R.id.input_layout_min_height); EditText minHeightEdit = (EditText) view.findViewById(R.id.edit_text_min_height); minHeightEdit.setText(String.valueOf(mFlexItem.minHeight)); minHeightEdit.addTextChangedListener(new FlexEditTextWatcher(minHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer)); final TextInputLayout maxWidthInput = (TextInputLayout) view.findViewById(R.id.input_layout_max_width); EditText maxWidthEdit = (EditText) view.findViewById(R.id.edit_text_max_width); maxWidthEdit.setText(String.valueOf(mFlexItem.maxWidth)); maxWidthEdit.addTextChangedListener(new FlexEditTextWatcher(maxWidthInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer)); final TextInputLayout maxHeightInput = (TextInputLayout) view.findViewById(R.id.input_layout_max_height); EditText maxHeightEdit = (EditText) view.findViewById(R.id.edit_text_max_height); maxHeightEdit.setText(String.valueOf(mFlexItem.maxHeight)); maxHeightEdit.addTextChangedListener(new FlexEditTextWatcher(maxHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer)); setNextFocusesOnEnterDown(orderEdit, flexGrowEdit, flexShrinkEdit, flexBasisPercentEdit, widthEdit, heightEdit, minWidthEdit, minHeightEdit, maxWidthEdit, maxHeightEdit); Spinner alignSelfSpinner = (Spinner) view.findViewById(R.id.spinner_align_self); ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.array_align_self, R.layout.spinner_item); alignSelfSpinner.setAdapter(arrayAdapter); alignSelfSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String selected = parent.getItemAtPosition(position).toString(); if (selected.equals(ALIGN_SELF_AUTO)) { mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_AUTO; } else if (selected.equals(ALIGN_SELF_FLEX_START)) { mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_FLEX_START; } else if (selected.equals(ALIGN_SELF_FLEX_END)) { mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_FLEX_END; } else if (selected.equals(ALIGN_SELF_CENTER)) { mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_CENTER; } else if (selected.equals(ALIGN_SELF_BASELINE)) { mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_BASELINE; } else if (selected.equals(ALIGN_SELF_STRETCH)) { mFlexItem.alignSelf = FlexboxLayout.LayoutParams.ALIGN_SELF_STRETCH; } } @Override public void onNothingSelected(AdapterView<?> parent) { // No op } }); CheckBox wrapBeforeCheckBox = (CheckBox) view.findViewById(R.id.checkbox_wrap_before); wrapBeforeCheckBox.setChecked(mFlexItem.wrapBefore); wrapBeforeCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mFlexItem.wrapBefore = isChecked; } }); int alignSelfPosition = arrayAdapter.getPosition(alignSelfAsString(mFlexItem.alignSelf)); alignSelfSpinner.setSelection(alignSelfPosition); view.findViewById(R.id.button_cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); final Button okButton = (Button) view.findViewById(R.id.button_ok); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (orderTextInput.isErrorEnabled() || flexGrowInput.isErrorEnabled() || flexBasisPercentInput.isErrorEnabled() || widthInput.isErrorEnabled() || heightInput.isErrorEnabled() || minWidthInput.isErrorEnabled() || minHeightInput.isErrorEnabled() || maxWidthInput.isErrorEnabled() || maxHeightInput.isErrorEnabled()) { Toast.makeText(getActivity(), R.string.invalid_values_exist, Toast.LENGTH_SHORT).show(); return; } if (mFlexItemChangedListener != null) { mFlexItemChangedListener.onFlexItemChanged(mFlexItem); } dismiss(); } }); return view; }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.CustomLocationFragment.java
/** * Setups up the Location Log to display previous locations, connects the UI * buttons, starts listening for location updates and finally calls setup * map. Gets the proper fragment manager and sets it to fragManager. * /*ww w . ja va 2 s .co m*/ */ public void onStart() { super.onStart(); GeoLocationLog log = GeoLocationLog.generateInstance(getActivity()); ArrayList<GeoLocation> logArray = log.getLogEntries(); FavouritesFragment favFrag = (FavouritesFragment) getFragmentManager().findFragmentByTag("favouritesFrag"); if (favFrag != null) { fragManager = getChildFragmentManager(); } else { fragManager = getFragmentManager(); } ListView lv = (ListView) getView().findViewById(R.id.custom_location_list_view); locationListenerService = new LocationListenerService(getActivity()); locationListenerService.startListening(); markers = new ArrayList<Marker>(); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // clicks a previous location item in the list GeoLocation logEntry = (GeoLocation) parent.getItemAtPosition(position); setBundleArguments(logEntry, "PREVIOUS_LOCATION"); fragManager.popBackStackImmediate(); } }); CustomLocationAdapter customLocationAdapter = new CustomLocationAdapter(getActivity(), logArray); lv.setAdapter(customLocationAdapter); setupMap(getMapEventsReceiver()); mapData.refreshMap(); }
From source file:fr.forexperts.ui.MarketOverviewFragment.java
public void showAddDialog() { LayoutInflater inflater = LayoutInflater.from(getActivity()); View alertView = inflater.inflate(R.layout.alertdialog_add_value, null); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(alertView);//from ww w .j a v a2 s . c o m final AlertDialog dialog = builder.create(); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); wmlp.gravity = Gravity.TOP | Gravity.CENTER; wmlp.x = 10; wmlp.y = 10; final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName); mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock); mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String text = (String) parent.getItemAtPosition(position); String[] result = text.split(" "); mCallback.onItemSelect(result[0]); dialog.dismiss(); } }); mStockName.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { SuggestStockTask task = new SuggestStockTask(); task.execute(mStockName.getText().toString()); } }); // TODO: Change hard coded width mStockName.setWidth(10000); dialog.show(); }
From source file:org.mythdroid.activities.Main.java
private Dialog createMddDialog() { final AlertDialog d = new AlertDialog.Builder(ctx).setItems(new String[] {}, null) .setIcon(drawable.ic_menu_agenda).setTitle(R.string.mddCmd).create(); d.getListView().setOnItemClickListener(new OnItemClickListener() { @Override/*from ww w. j a v a 2s.c o m*/ public void onItemClick(AdapterView<?> av, View v, int pos, long id) { try { MDDManager.mddCommand(Globals.getFrontend(ctx).addr, (String) av.getItemAtPosition(pos)); } catch (IOException e) { ErrUtil.postErr(ctx, e); } d.dismiss(); } }); return d; }
From source file:net.sourceforge.servestream.fragment.BrowseFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ListView list = getListView(); list.setFastScrollEnabled(true);/*from w ww .j a va 2 s. c o m*/ list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { UriBean uri = (UriBean) parent.getItemAtPosition(position); browseTo(uri); } }); registerForContextMenu(list); if (mAdapter == null) { mAdapter = new BrowseAdapter(getActivity(), new ArrayList<UriBean>(), this); } list.setAdapter(mAdapter); }
From source file:vn.alovoice.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // String locationSetting = Utility.getPreferredLocation(getActivity()); ////from www.j a va 2 s . c o m // // Sort order: Ascending, by date. // String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC"; // Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate( // locationSetting, System.currentTimeMillis()); // // Cursor cur = getActivity().getContentResolver().query(weatherForLocationUri, // null, null, null, sortOrder); // // // The CursorAdapter will take data from our cursor and populate the ListView // // However, we cannot use FLAG_AUTO_REQUERY since it is deprecated, so we will end // // up with an empty list the first time we run. // mForecastAdapter = new ForecastAdapter(getActivity(), cur, 0); // The CursorAdapter will take data from our cursor and populate the ListView. // The ForecastAdapter will take data from a source and // use it to populate the ListView it's attached to. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. //ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); //listView.setAdapter(mForecastAdapter); mListView = (ListView) rootView.findViewById(R.id.listview_forecast); mListView.setAdapter(mForecastAdapter); // We'll call our MainActivity mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = Utility.getPreferredLocation(getActivity()); //Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate( ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); //startActivity(intent); } mPosition = position; } }); // If there's instance state, mine it for useful information. // The end-goal here is that the user never knows that turning their device sideways // does crazy lifecycle related things. It should feel like some stuff stretched out, // or magically appeared to take advantage of room, but data or place in the app was never // actually *lost*. if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) { // The listview probably hasn't even been populated yet. Actually perform the // swapout in onLoadFinished. mPosition = savedInstanceState.getInt(SELECTED_KEY); } mForecastAdapter.setUseTodayLayout(mUseTodayLayout); return rootView; }
From source file:net.inbox.Pager.java
public void populate_list_view() { ArrayList<Inbox> list_accounts = db.get_all_accounts(); if (list_accounts.size() == 0) { tv_no_account.setVisibility(View.VISIBLE); if (inbox_list_view != null) inbox_list_view.setAdapter(null); } else {/* w w w . j a va 2 s.co m*/ tv_no_account.setVisibility(View.GONE); // Update data set if (al_accounts_items.size() > 0) { al_accounts_items.clear(); } // Sort accounts' list Collections.sort(list_accounts, new Comparator<Inbox>() { public int compare(Inbox inn1, Inbox inn2) { return inn1.get_email().compareTo(inn2.get_email()); } }); for (int i = 0; i < list_accounts.size(); i++) { Inbox nfo = list_accounts.get(i); al_accounts_items.add(new InboxListItem(nfo.get_id(), nfo.get_email(), nfo.get_unseen())); } // Add list adapter if (inbox_list_view.getAdapter() == null) { inbox_adapter = new InboxList(this, al_accounts_items); inbox_list_view.setAdapter(inbox_adapter); } inbox_adapter.notifyDataSetChanged(); inbox_list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { InboxListItem inbox_itm = (InboxListItem) parent.getItemAtPosition(position); Intent i = new Intent(getApplicationContext(), InboxUI.class); Bundle b = new Bundle(); b.putInt("db_id", inbox_itm.get_id()); startActivityForResult(i.putExtras(b), 10); overridePendingTransition(R.anim.left_in, R.anim.left_out); } }); } // Update message counter set_count(); }
From source file:de.baumann.hhsmoodle.activities.Activity_todo.java
private void setupListViewListener() { lvItems.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override/*from ww w . j a v a 2 s . c o m*/ public boolean onItemLongClick(AdapterView<?> adapter, View item, final int pos, long id) { final String text = (String) adapter.getItemAtPosition(pos); // Remove the item within array at position items.remove(pos); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG) .setAction(R.string.todo_removed_back, new View.OnClickListener() { @Override public void onClick(View view) { items.add(pos, text); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); } }); snackbar.show(); return true; } }); lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> adapter, View item, final int pos, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity_todo.this); View dialogView = View.inflate(Activity_todo.this, R.layout.dialog_edit_text_singleline, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); ImageButton ib_paste = (ImageButton) dialogView.findViewById(R.id.imageButtonPaste); ib_paste.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final CharSequence[] options = { getString(R.string.paste_date), getString(R.string.paste_time) }; new android.app.AlertDialog.Builder(Activity_todo.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.paste_date))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); String dateNow = format.format(date); edit_title.getText().insert(edit_title.getSelectionStart(), dateNow); } if (options[item].equals(getString(R.string.paste_time))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); String timeNow = format.format(date); edit_title.getText().insert(edit_title.getSelectionStart(), timeNow); } } }).show(); } }); String text = (String) adapter.getItemAtPosition(pos); edit_title.setText(text); builder.setView(dialogView); builder.setTitle(R.string.number_edit_entry); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); // Remove the item within array at position items.remove(pos); items.add(pos, inputTag); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(Activity_todo.this, edit_title); } }); }
From source file:org.solovyev.android.calculator.math.edit.AbstractMathEntityListFragment.java
@Override public void onViewCreated(View root, Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); fragmentHelper.onViewCreated(this, root); final ListView lv = getListView(); lv.setTextFilterEnabled(true);//from w ww. j a va2s.c o m lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { final AMenuItem<T> onClick = getOnClickAction(); if (onClick != null) { onClick.onClick(((T) parent.getItemAtPosition(position)), getActivity()); } } }); getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final T item = (T) parent.getItemAtPosition(position); final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item); if (!menuItems.isEmpty()) { final ContextMenuBuilder<LabeledMenuItem<T>, T> menuBuilder = ContextMenuBuilder.newInstance( AbstractMathEntityListFragment.this.getActivity(), "math-entity-menu", ListContextMenu.newInstance(menuItems)); menuBuilder.build(item).show(); } return true; } }); }
From source file:oss.ridendivideapp.PlacesAutoCompleteActivity.java
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { /* Get selected FROM and TO address from matching list values */ if (view == gr_frm_acView) { gr_frm_addr = (String) adapterView.getItemAtPosition(position); } else if (view == gr_to_acView) { gr_to_addr = (String) adapterView.getItemAtPosition(position); }/*w w w. jav a 2s.c o m*/ }