List of usage examples for android.support.v4.widget SimpleCursorAdapter getItem
public Object getItem(int position)
From source file:au.com.cybersearch2.classyfy.MainActivityTest.java
public void test_search() throws Throwable { final MainActivity mainActivity = getActivity(); Instrumentation instrumentation = getInstrumentation(); ActivityMonitor am = instrumentation.addMonitor(TitleSearchResultsActivity.class.getName(), null, false); assertThat(instrumentation.invokeMenuActionSync(mainActivity, R.id.action_search, 0)).isTrue(); ActionBar actionBar = mainActivity.getSupportActionBar(); assertThat(actionBar).isNotNull();//from w ww. j a va 2s.c o m final FragmentManager sfm = mainActivity.getSupportFragmentManager(); runTestOnUiThread(new Runnable() { public void run() { sfm.executePendingTransactions(); } }); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_I); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_N); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_F); instrumentation.sendCharacterSync(KeyEvent.KEYCODE_ENTER); runTestOnUiThread(new Runnable() { public void run() { sfm.executePendingTransactions(); } }); TitleSearchResultsActivity titleSearchResultsActivity = (TitleSearchResultsActivity) getInstrumentation() .waitForMonitorWithTimeout(am, 10000); assertThat(titleSearchResultsActivity).isNotNull(); assertThat(titleSearchResultsActivity.taskHandle).isNotNull(); synchronized (titleSearchResultsActivity.taskHandle) { titleSearchResultsActivity.taskHandle.wait(10000); } assertThat(titleSearchResultsActivity.taskHandle.getStatus()).isEqualTo(WorkStatus.FINISHED); SimpleCursorAdapter adapter = titleSearchResultsActivity.adapter; for (int i = 0; i < adapter.getCount(); i++) { Cursor cursor = (Cursor) adapter.getItem(i); int column = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1); assertThat(INF_LIST[i]).isEqualTo(cursor.getString(column)); } }
From source file:com.money.manager.ex.budget.BudgetListFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; // get selected item name SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter(); Cursor cursor = (Cursor) adapter.getItem(info.position); menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(Budget.BUDGETYEARNAME))); MenuHelper menuHelper = new MenuHelper(getActivity(), menu); menuHelper.addEditToContextMenu();//from w w w .ja v a2 s. c om menuHelper.addDeleteToContextMenu(); //todo menu.add(Menu.NONE, ContextMenuIds.COPY, Menu.NONE, getString(R.string.copy)); }
From source file:com.money.manager.ex.account.AccountListFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; // get selected item name SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter(); Cursor cursor = (Cursor) adapter.getItem(info.position); menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(Account.ACCOUNTNAME))); MenuHelper menuHelper = new MenuHelper(getActivity(), menu); menuHelper.addEditToContextMenu();//from www. ja v a 2 s.c om menuHelper.addDeleteToContextMenu(); }
From source file:com.esri.arcgisruntime.sample.findaddress.MainActivity.java
/** * Sets up the address SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. */// www . j a v a 2s.c o m private void setupAddressSearchView() { mAddressGeocodeParameters = new GeocodeParameters(); // get place name and address attributes mAddressGeocodeParameters.getResultAttributeNames().add("PlaceName"); mAddressGeocodeParameters.getResultAttributeNames().add("StAddr"); // return only the closest result mAddressGeocodeParameters.setMaxResults(1); mAddressSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { // geocode typed address geoCodeTypedAddress(address); // clear focus from search views mAddressSearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the results of the async operation List<SuggestResult> suggestResults = suggestionsFuture.get(); MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each address suggestion to a new row for (SuggestResult result : suggestResults) { suggestionsCursor.addRow(new Object[] { key++, result.getLabel() }); } // define SimpleCursorAdapter String[] cols = new String[] { COLUMN_NAME_ADDRESS }; int[] to = new int[] { R.id.suggestion_address }; final SimpleCursorAdapter suggestionAdapter = new SimpleCursorAdapter( MainActivity.this, R.layout.suggestion, suggestionsCursor, cols, to, 0); mAddressSearchView.setSuggestionsAdapter(suggestionAdapter); // handle an address suggestion being chosen mAddressSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // get the selected row MatrixCursor selectedRow = (MatrixCursor) suggestionAdapter .getItem(position); // get the row's index int selectedCursorIndex = selectedRow.getColumnIndex(COLUMN_NAME_ADDRESS); // get the string from the row at index String address = selectedRow.getString(selectedCursorIndex); // use clicked suggestion as query mAddressSearchView.setQuery(address, true); return true; } }); } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); } return true; } }); }
From source file:com.esri.arcgisruntime.sample.findplace.MainActivity.java
/** * Sets up the proximity SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. *///from w ww . jav a 2 s.c o m private void setupProximity() { mProximitySuggestParameters = new SuggestParameters(); mProximitySuggestParameters.getCategories().add("Populated Place"); mProximityGeocodeParameters = new GeocodeParameters(); // get all attributes mProximityGeocodeParameters.getResultAttributeNames().add("*"); mProximitySearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { geoCodeTypedAddress(address); // clear focus from search views mPoiSearchView.clearFocus(); mProximitySearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { mProximitySearchViewEmpty = false; final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText, mProximitySuggestParameters); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the list of suggestions List<SuggestResult> suggestResults = suggestionsFuture.get(); MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each SuggestResult to a new row for (SuggestResult result : suggestResults) { suggestionsCursor.addRow(new Object[] { key++, result.getLabel() }); } // define SimpleCursorAdapter String[] cols = new String[] { COLUMN_NAME_ADDRESS }; int[] to = new int[] { R.id.suggestion_address }; final SimpleCursorAdapter suggestionAdapter = new SimpleCursorAdapter( MainActivity.this, R.layout.suggestion, suggestionsCursor, cols, to, 0); mProximitySearchView.setSuggestionsAdapter(suggestionAdapter); mProximitySearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // get the selected row MatrixCursor selectedRow = (MatrixCursor) suggestionAdapter .getItem(position); // get the row's index int selectedCursorIndex = selectedRow.getColumnIndex(COLUMN_NAME_ADDRESS); // get the string from the row at index final String address = selectedRow.getString(selectedCursorIndex); mLocatorTask.addDoneLoadingListener(new Runnable() { @Override public void run() { if (mLocatorTask.getLoadStatus() == LoadStatus.LOADED) { // geocode the selected address to get location of address final ListenableFuture<List<GeocodeResult>> geocodeFuture = mLocatorTask .geocodeAsync(address, mProximityGeocodeParameters); geocodeFuture.addDoneListener(new Runnable() { @Override public void run() { try { // Get the results of the async operation List<GeocodeResult> geocodeResults = geocodeFuture .get(); if (geocodeResults.size() > 0) { // use geocodeResult to focus search area GeocodeResult geocodeResult = geocodeResults .get(0); // update preferred search area to the geocode result mPreferredSearchProximity = geocodeResult .getDisplayLocation(); mPoiGeocodeParameters.setSearchArea( mPreferredSearchProximity); // set the address string to the SearchView, but don't submit as a query mProximitySearchView.setQuery(address, false); // call POI search query mPoiSearchView.setQuery(mPoiAddress, true); // clear focus from search views mProximitySearchView.clearFocus(); mPoiSearchView.clearFocus(); } else { Toast.makeText(getApplicationContext(), getString(R.string.location_not_found) + address, Toast.LENGTH_LONG).show(); } } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "Geocode error: " + e.getMessage()); Toast.makeText(getApplicationContext(), getString(R.string.geo_locate_error), Toast.LENGTH_LONG).show(); } } }); } } }); return true; } }); } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); // if search view is empty, set flag } else { mProximitySearchViewEmpty = true; } return true; } }); }
From source file:com.esri.arcgisruntime.sample.findplace.MainActivity.java
/** * Sets up the POI SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. *//*from w w w .j av a 2 s.c om*/ private void setupPoi() { mPoiSuggestParameters = new SuggestParameters(); // filter categories for POI mPoiSuggestParameters.getCategories().add("POI"); mPoiGeocodeParameters = new GeocodeParameters(); // get all attributes mPoiGeocodeParameters.getResultAttributeNames().add("*"); mPoiSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { // if proximity SearchView text box is empty, use the device location if (mProximitySearchViewEmpty) { mPreferredSearchProximity = mLocationDisplay.getMapLocation(); mProximitySearchView.setQuery("Using current location...", false); } // keep track of typed address mPoiAddress = address; // geocode typed address geoCodeTypedAddress(address); // clear focus from search views mPoiSearchView.clearFocus(); mProximitySearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(final String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { mPoiSuggestParameters.setSearchArea(mCurrentExtentGeometry); final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText, mPoiSuggestParameters); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the results of the async operation List<SuggestResult> suggestResults = suggestionsFuture.get(); if (!suggestResults.isEmpty()) { MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each poi_suggestion result to a new row for (SuggestResult result : suggestResults) { suggestionsCursor.addRow(new Object[] { key++, result.getLabel() }); } // define SimpleCursorAdapter String[] cols = new String[] { COLUMN_NAME_ADDRESS }; int[] to = new int[] { R.id.suggestion_address }; final SimpleCursorAdapter suggestionAdapter = new SimpleCursorAdapter( MainActivity.this, R.layout.suggestion, suggestionsCursor, cols, to, 0); mPoiSearchView.setSuggestionsAdapter(suggestionAdapter); // handle a poi_suggestion being chosen mPoiSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // get the selected row MatrixCursor selectedRow = (MatrixCursor) suggestionAdapter .getItem(position); // get the row's index int selectedCursorIndex = selectedRow .getColumnIndex(COLUMN_NAME_ADDRESS); // get the string from the row at index mPoiAddress = selectedRow.getString(selectedCursorIndex); mPoiSearchView.setQuery(mPoiAddress, true); return true; } }); } else { mPoiAddress = newText; } } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); } return true; } }); }