List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:com.heske.alexandria.activities.ListOfBooksFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { mBookListAdapter.swapCursor(cursor); if (mBookListAdapter.getCount() == 0) { mLastPosition = 0;//from w w w. ja v a2 s . com return; } cursor.moveToPosition(mLastPosition); if (mLastPosition != ListView.INVALID_POSITION) { mBookListView.smoothScrollToPosition(mLastPosition); int cursorIndex = cursor.getColumnIndex(AlexandriaContract.BookEntry._ID); String ean = cursor.getString(cursorIndex); if (mSelectBook) mCallback.onBookSelected(ean, mUserSelected); } }
From source file:net.potterpcs.recipebook.RecipeViewer.java
@Override protected void onResume() { super.onResume(); // This is essentially a single-threaded emulation of what // the Loader framework already does. Hopefully it will work // until I rewrite the app to use Loaders everywhere. directionsCursor = data.getRecipeDirections(rid); directionsAdapter.swapCursor(directionsCursor); ingredientsCursor = data.getRecipeIngredients(rid); ingredientsAdapter.swapCursor(ingredientsCursor); if (dirPhotoPref) { lvdirections.setOnItemClickListener(new OnItemClickListener() { @Override// www.j av a 2 s .c om public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Cursor c = data.getRecipeDirections(rid); c.moveToPosition(position); String uri = c.getString(c.getColumnIndex(RecipeData.DT_PHOTO)); if (uri != null && !uri.equals("")) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); PhotoDialog pd = PhotoDialog.newInstance(uri); pd.show(ft, "dialog"); } c.close(); } }); } }
From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java
public void setCurrentServerProfile(long id) { Cursor cursor = queryServerProfile(id); if (cursor != null) { try {/*from w w w .jav a2 s . c o m*/ if (cursor.getCount() > 0) { cursor.moveToPosition(0); setCurrentServerProfile(cursor); } } finally { cursor.close(); } } }
From source file:org.alfresco.mobile.android.application.fragments.operation.OperationsFragment.java
protected void cancelAll() { Cursor cursor = ((CursorAdapter) adapter).getCursor(); Uri uri = null;//from www . j a va2 s. co m if (!cursor.isFirst()) { cursor.moveToPosition(-1); } for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); uri = Uri.parse( OperationsContentProvider.CONTENT_URI + "/" + cursor.getInt(OperationSchema.COLUMN_ID_ID)); Operator.with(getActivity()).cancel(uri.toString()); } cancelAll.setVisibility(View.GONE); dismissAll.setVisibility(View.GONE); }
From source file:org.alfresco.mobile.android.application.fragments.operation.OperationsFragment.java
protected void dismissAll() { Cursor cursor = ((CursorAdapter) adapter).getCursor(); Uri uri = null;/*from w w w. j av a2s . c o m*/ if (!cursor.isFirst()) { cursor.moveToPosition(-1); } for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); uri = Uri.parse( OperationsContentProvider.CONTENT_URI + "/" + cursor.getInt(OperationSchema.COLUMN_ID_ID)); getActivity().getContentResolver().delete(uri, null, null); } cancelAll.setVisibility(View.GONE); dismissAll.setVisibility(View.GONE); }
From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java
public void setCurrentInfoSnapshot(long profileId) { Cursor cursor = queryServerProfile(profileId); if (cursor != null) { try {//from w w w .j a v a 2 s .c o m if (cursor.getCount() > 0) { cursor.moveToPosition(0); serverInfoSnapshot.setProfile(new ServerProfiles(cursor)); } } finally { cursor.close(); } } }
From source file:com.mingbai.library.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 w w.ja v a2s . 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)); String contactName = itemCursor.getString( itemCursor.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.DISPLAY_NAME)); String avatarURI = itemCursor.getString( itemCursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.PHOTO_THUMBNAIL_URI)); int contactKind = itemCursor .getInt(itemCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); for (ResultItem previousItem : resultItems) { if (contactNumber.equals(previousItem.getResult())) { continue itemCursorLoop; } } resultItems.add(new ContactResult.ResultItem(contactNumber, contactName, avatarURI, contactKind)); } 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.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java
@Override public void onEdit(int position) { Cursor cursor = mAdapter.getCursor(); cursor.moveToPosition(position); long profileId = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID)); ServerProfileActivity_.intent(getActivity()).profileId(profileId).start(); mAdapter.finishActionMode();//from w w w .ja v a2s. co m }
From source file:me.vancexu.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The SimpleCursorAdapter will take data from the database through the // Loader 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. mListView = (ListView) rootView.findViewById(R.id.listview_forecast); mListView.setAdapter(mForecastAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from www .j a v a2 s. c om 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.jaspersoft.android.jaspermobile.util.ProfileHelper.java
public void updateCurrentInfoSnapshot(long profileId, ServerInfo serverInfo) { Cursor cursor = queryServerProfile(profileId); if (cursor != null) { try {//from ww w . j av a 2s . c o m if (cursor.getCount() > 0) { cursor.moveToPosition(0); ServerProfiles profile = new ServerProfiles(cursor); profile.setVersioncode(serverInfo.getVersionCode()); profile.setEdition(serverInfo.getEdition()); Uri uri = Uri.withAppendedPath(JasperMobileDbProvider.SERVER_PROFILES_CONTENT_URI, String.valueOf(profileId)); context.getContentResolver().update(uri, profile.getContentValues(), null, null); serverInfoSnapshot.setProfile(profile); } } finally { cursor.close(); } } }