List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:example.com.sunshine.app.ForecastFragment.java
private void openPreferredLocationInMap() { if (mForecastAdapter != null) { // Using the URI scheme for showing a location found on a map. This super-handy // intent can is detailed in the "Common Intents" page of Android's developer site: // http://developer.android.com/guide/components/intents-common.html#Maps Cursor c = mForecastAdapter.getCursor(); c.moveToPosition(0); String longCord = c.getString(COL_COORD_LONG); String latCord = c.getString(COL_COORD_LAT); Uri geoLocation = Uri.parse("geo:" + latCord + ", " + longCord).buildUpon().build(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation);//from w w w . ja va2 s .co m if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } else { Log.d(LOG_TAG, "Couldn't call " + geoLocation + ", no receiving apps installed!"); } c.close(); } }
From source file:com.jhk.whysoformal.activity.musiclist.musicentry.fragment.MusicPlayerFragment.java
private void updateTitle() { AudioContext context = AudioContext.getInstance(); Cursor cursor = context.getCursor(); cursor.moveToPosition(context.peekPlayEntry().getPosition()); getActivity().setTitle(/*from w ww. ja v a 2s .com*/ cursor.getString(cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DISPLAY_NAME))); }
From source file:com.ev.contactsmultipicker.ContactListFragment.java
@Override public void onItemClick(AdapterView<?> adapterView, View view, int pos, long rowId) { CheckBox checkbox = (CheckBox) view.findViewById(R.id.contactCheck); Cursor cursor = mCursorAdapter.getCursor(); cursor.moveToPosition(pos); String id = cursor.getString(0); if (checkbox.isChecked()) { checkbox.setChecked(false);/*from w ww .j a va 2s . c o m*/ results.remove(id); } else { checkbox.setChecked(true); Cursor itemCursor = getActivity().getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null); List<ContactResult.ResultItem> resultItems = new LinkedList<ContactResult.ResultItem>(); itemCursorLoop: while (itemCursor.moveToNext()) { String contactNumber = itemCursor .getString(itemCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); int contactKind = itemCursor .getInt(itemCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); String displayName = itemCursor .getString(itemCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); Bitmap image = retrieveContactPhoto(id); for (ResultItem previousItem : resultItems) { if (contactNumber.equals(previousItem.getResult())) { continue itemCursorLoop; } } resultItems.add(new ContactResult.ResultItem(contactNumber, contactKind, displayName, image)); } itemCursor.close(); if (resultItems.size() > 1) { // contact has multiple items - user needs to choose from them chooseFromMultipleItems(resultItems, checkbox, id); } else { // only one result or all items are similar for this contact results.put(id, new ContactResult(id, resultItems)); } } }
From source file:com.rsegismont.androlife.programlist.FragmentListProgrammes.java
public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong) { if (SdkUtils.isTabletLandscape(getActivity())) { ((ProgramListActivity) getActivity()).setDetailsSelection(paramInt); } else {// w ww . j a v a 2 s.c o m Cursor localCursor = getCursor(); int i = localCursor.getPosition(); localCursor.moveToPosition(paramInt); int j = localCursor.getColumnIndex(SharedInformation.DatabaseColumn.DATE_UTC.stringValue); Intent localIntent = new Intent(getActivity(), ProgrammesDetailActivity.class); localIntent.putExtra(Constantes.DETAIL_DATE_TIME, localCursor.getLong(j)); localIntent.putExtra(Constantes.TYPE, this.mType); if (i >= 0) localCursor.moveToPosition(i); startActivity(localIntent); } }
From source file:ua.com.elius.sunshine.app.ForecastFragment.java
private void openPreferredLocationInMap() { if (mForecastAdapter != null) { Cursor c = mForecastAdapter.getCursor(); if (c != null) { c.moveToPosition(0); String latitude;//from w ww. java 2 s . c o m String longitude; latitude = c.getString(COL_COORD_LAT); longitude = c.getString(COL_COORD_LONG); Uri geoLocation = Uri.parse("geo:" + latitude + "," + longitude); Log.d(LOG_TAG, geoLocation.toString()); Intent viewLocationIntent; viewLocationIntent = new Intent(); viewLocationIntent.setAction(Intent.ACTION_VIEW); viewLocationIntent.setData(geoLocation); if (viewLocationIntent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(viewLocationIntent); } } } }
From source file:org.que.activities.fragments.CalendarBookedFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { String itemID = "NULL"; Fragment frg = new Fragment(); Bundle args = new Bundle(); Object o = getListView().getItemAtPosition(position); super.onListItemClick(l, v, position, id); Cursor c = ((SimpleCursorAdapter) l.getAdapter()).getCursor(); c.moveToPosition(position); String description = c.getString(5); //gets the description field of the calendar item try {// w ww . j a v a 2 s . co m //check whether item is a session or a paper if (description.contains("session")) { //itemID cleans up the description String first to get the Database ID of the Session itemID = description .replace(getActivity().getString(R.string.calendarEventDescription) + "sessionID", ""); SessionEntity entity = ConferenceDAO.getSessionByID(itemID, getActivity()); args.putSerializable(SessionFragment.ARG_SESSIONVIEW_FRAGMENT, entity); frg = new SessionFragment(); } else if (description.contains("paper")) { itemID = description.replace(getActivity().getString(R.string.calendarEventDescription) + "paperID", ""); PaperEntity entity = new PaperEntity(); entity = ConferenceDAO.getPaperByID(itemID, getActivity()); args.putSerializable(PaperFragment.ARG_PAPERVIEW_FRAGMENT, entity); frg = new PaperFragment(); } } catch (NullPointerException e) { AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); b.setMessage( "Something went wrong when trying to retrieve this event. Please re-favorite the event to re-add it to the calendar."); b.setTitle("Oops"); b.setNeutralButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); b.show(); } if (frg != null) { frg.setArguments(args); FragmentManager mgr = ((FragmentActivity) getActivity()).getSupportFragmentManager(); Fragment old = mgr.findFragmentById(R.id.content_frame); FragmentTransaction trx = mgr.beginTransaction(); if (old != null) trx.remove(old); trx.add(R.id.content_frame, frg).addToBackStack(null) //TODO .commit(); } }
From source file:com.google.samples.apps.iosched.ui.SearchActivity.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Cursor c = mResultsAdapter.getCursor(); c.moveToPosition(position); boolean isTopicTag = c.getInt(SearchTopicsSessionsQuery.IS_TOPIC_TAG) == 1; String tagOrSessionId = c.getString(SearchTopicsSessionsQuery.TAG_OR_SESSION_ID); if (isTopicTag) { Intent intent = new Intent(this, ExploreSessionsActivity.class); intent.putExtra(ExploreSessionsActivity.EXTRA_FILTER_TAG, tagOrSessionId); startActivity(intent);/*from ww w. j av a 2 s.co m*/ } else if (tagOrSessionId != null) { Intent intent = new Intent(this, SessionDetailActivity.class); intent.setData(ScheduleContract.Sessions.buildSessionUri(tagOrSessionId)); startActivity(intent); } }
From source file:com.digitalconstruction.myapplication.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The ArrayAdapter 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 mListView = (ListView) rootView.findViewById(R.id.listview_forecast); mListView.setAdapter(mForecastAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w w w .j a v a 2 s. co m*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Cursor cursor = mForecastAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { ((Callback) getActivity()).onItemSelected(cursor.getString(COL_WEATHER_DATE)); } 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:com.learnNcode.mediachooser.fragment.ImageFragment.java
private void setAdapter(Cursor imagecursor) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false); mGalleryModelList.add(galleryModel); }/*from ww w .ja v a 2s . c om*/ mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT) && (!galleryModel.status)) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_reach_error), Toast.LENGTH_SHORT).show(); } else { // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); } else { mSelectedItems.remove(galleryModel.url.toString().trim()); } if (mCallback != null) { mCallback.onImageSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } } }); }
From source file:org.mozilla.gecko.home.PinSiteDialog.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mSearch = (EditText) view.findViewById(R.id.search); mSearch.addTextChangedListener(new TextWatcher() { @Override/*from w ww .j a va 2s . co m*/ public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { setSearchTerm(mSearch.getText().toString()); filter(mSearchTerm); } }); mSearch.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_ENTER || mOnSiteSelectedListener == null) { return false; } // If the user manually entered a search term or URL, wrap the value in // a special URI until we can get a valid URL for this bookmark. final String text = mSearch.getText().toString().trim(); if (!TextUtils.isEmpty(text)) { final String url = StringUtils.encodeUserEnteredUrl(text); mOnSiteSelectedListener.onSiteSelected(url, text); dismiss(); } return true; } }); mSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { getDialog().getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); mList = (HomeListView) view.findViewById(R.id.list); mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mOnSiteSelectedListener != null) { final Cursor c = mAdapter.getCursor(); if (c == null || !c.moveToPosition(position)) { return; } final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL)); final String title = c.getString(c.getColumnIndexOrThrow(URLColumns.TITLE)); mOnSiteSelectedListener.onSiteSelected(url, title); } // Dismiss the fragment and the dialog. dismiss(); } }); }