List of usage examples for android.support.v4.widget CursorAdapter swapCursor
public Cursor swapCursor(Cursor newCursor)
From source file:com.laevatein.internal.ui.helper.AlbumListViewHelper.java
public static void setCursor(Fragment fragment, Cursor cursor) { ListView listView = (ListView) FragmentUtils.findViewById(fragment, R.id.l_list_album); CursorAdapter adapter = (CursorAdapter) listView.getAdapter(); adapter.swapCursor(cursor); }
From source file:com.laevatein.internal.ui.helper.PhotoGridViewHelper.java
public static void setCursor(Fragment fragment, Cursor cursor) { GridView gridView = (GridView) fragment.getView().findViewById(R.id.l_grid_photo); CursorAdapter adapter = (CursorAdapter) gridView.getAdapter(); adapter.swapCursor(cursor); }
From source file:org.ohmage.db.DbHelper.java
/** * Swaps newCursor into the given adapter and closes the old cursor if one exists * @param adapter the adapter into which to swap the new cursor * @param newCursor the cursor to swap into the adapter *//*w ww. ja v a 2s.c o m*/ public static void swapCursorSafe(CursorAdapter adapter, Cursor newCursor) { Cursor oldCursor = adapter.swapCursor(newCursor); if (oldCursor != null && !oldCursor.isClosed()) oldCursor.close(); }
From source file:com.wheelly.fragments.LocationsListFragment.java
@Subscribe public void onLoadFinished(LocationsLoadedEvent event) { final CursorAdapter a = (CursorAdapter) getListAdapter(); a.swapCursor(event.cursor); }
From source file:com.hplasplas.weather.activitys.SearchPlaceActivity.java
private void closeCursor(SearchView searchView) { if (searchView != null) { CursorAdapter adapter = searchView.getSuggestionsAdapter(); if (adapter != null) { Cursor cursor = adapter.swapCursor(null); if (cursor != null && !cursor.isClosed()) { cursor.close();//from w w w .j av a2 s . c o m } } } }
From source file:eu.masconsult.bgbanking.activity.fragment.AccountsListFragment.java
private void swapCursorFromLoader(Loader<Cursor> loader, Cursor cursor) { CursorAdapter adapter = getCursorAdapter(loader); if (adapter == null) { return;//from w w w . j a v a2 s . co m } adapter.swapCursor(cursor); }
From source file:com.smedic.tubtub.Pane.java
private Loader suggestionLoader(final List<String> suggestions, final CursorAdapter suggestionAdapter, final String query) { return getSupportLoaderManager().restartLoader(4, null, new LoaderManager.LoaderCallbacks<List<String>>() { @Override//from w ww . j av a2s .c om public Loader<List<String>> onCreateLoader(final int id, final Bundle args) { return new SuggestionsLoader(getApplicationContext(), query); } @Override public void onLoadFinished(Loader<List<String>> loader, List<String> data) { if (data == null) return; suggestions.clear(); suggestions.addAll(data); String[] columns = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 }; MatrixCursor cursor = new MatrixCursor(columns); for (int i = 0; i < data.size(); i++) { String[] tmp = { Integer.toString(i), data.get(i) }; cursor.addRow(tmp); } suggestionAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<List<String>> loader) { suggestions.clear(); suggestions.addAll(Collections.<String>emptyList()); } }); }
From source file:com.teocci.utubinbg.MainActivity.java
/** * Options menu in action bar/*from w w w.j av a 2 s . c o m*/ * * @param menu * @return */ @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); if (searchView != null) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); } //suggestions final CursorAdapter suggestionAdapter = new SimpleCursorAdapter(this, R.layout.dropdown_menu, null, new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 }, new int[] { android.R.id.text1 }, 0); final List<String> suggestions = new ArrayList<>(); searchView.setSuggestionsAdapter(suggestionAdapter); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { searchView.setQuery(suggestions.get(position), false); searchView.clearFocus(); Intent suggestionIntent = new Intent(Intent.ACTION_SEARCH); suggestionIntent.putExtra(SearchManager.QUERY, suggestions.get(position)); handleIntent(suggestionIntent); return true; } }); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { return false; //if true, no new intent is started } @Override public boolean onQueryTextChange(String suggestion) { // check network connection. If not available, do not query. // this also disables onSuggestionClick triggering if (suggestion.length() > 2) { //make suggestions after 3rd letter if (networkConf.isNetworkAvailable()) { new JsonAsyncTask(new JsonAsyncTask.AsyncResponse() { @Override public void processFinish(ArrayList<String> result) { suggestions.clear(); suggestions.addAll(result); String[] columns = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 }; MatrixCursor cursor = new MatrixCursor(columns); for (int i = 0; i < result.size(); i++) { String[] tmp = { Integer.toString(i), result.get(i) }; cursor.addRow(tmp); } suggestionAdapter.swapCursor(cursor); } }).execute(suggestion); return true; } } return false; } }); return true; }