Java Code Examples for android.widget.SimpleCursorAdapter#setFilterQueryProvider()

The following examples show how to use android.widget.SimpleCursorAdapter#setFilterQueryProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Collins.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param context this
 * @param layout  support_simple_spinner_dropdown_item
 * @return
 */
public ListAdapter getAutoCompleteAdapter(Context context, int layout) {
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(context, layout,
                    null,
                    new String[]{FIELD_HWD},
                    new int[]{android.R.id.text1},
                    0
            );
    adapter.setFilterQueryProvider(
            new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    return getFilterCursor(constraint.toString());
                }
            }
    );
    adapter.setCursorToStringConverter(
            new SimpleCursorAdapter.CursorToStringConverter() {
                @Override
                public CharSequence convertToString(Cursor cursor) {
                    return cursor.getString(1);
                }
            }
    );

    return adapter;
}
 
Example 2
Source File: WebsterLearners.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
public ListAdapter getAutoCompleteAdapter(Context context, int layout) {
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(context, layout,
                    null,
                    new String[]{"hwd"},
                    new int[]{android.R.id.text1},
                    0
            );
    adapter.setFilterQueryProvider(
            new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    return getFilterCursor(constraint.toString());
                }
            }
    );
    adapter.setCursorToStringConverter(
            new SimpleCursorAdapter.CursorToStringConverter() {
                @Override
                public CharSequence convertToString(Cursor cursor) {
                    return cursor.getString(1);
                }
            }
    );

    return adapter;
}
 
Example 3
Source File: Ode2.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param context this
 * @param layout  support_simple_spinner_dropdown_item
 * @return
 */
public ListAdapter getAutoCompleteAdapter(Context context, int layout) {
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(context, layout,
                    null,
                    new String[]{FIELD_HWD},
                    new int[]{android.R.id.text1},
                    0
            );
    adapter.setFilterQueryProvider(
            new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    return getFilterCursor(constraint.toString());
                }
            }
    );
    adapter.setCursorToStringConverter(
            new SimpleCursorAdapter.CursorToStringConverter() {
                @Override
                public CharSequence convertToString(Cursor cursor) {
                    return cursor.getString(1);
                }
            }
    );

    return adapter;
}
 
Example 4
Source File: CollinsEnEn.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param context this
 * @param layout  support_simple_spinner_dropdown_item
 * @return
 */
public ListAdapter getAutoCompleteAdapter(Context context, int layout) {
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(context, layout,
                    null,
                    new String[]{FIELD_HWD},
                    new int[]{android.R.id.text1},
                    0
            );
    adapter.setFilterQueryProvider(
            new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    return getFilterCursor(constraint.toString());
                }
            }
    );
    adapter.setCursorToStringConverter(
            new SimpleCursorAdapter.CursorToStringConverter() {
                @Override
                public CharSequence convertToString(Cursor cursor) {
                    return cursor.getString(1);
                }
            }
    );

    return adapter;
}
 
Example 5
Source File: CustomDictionary.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ListAdapter getAutoCompleteAdapter(Context context, int layout) {
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(context, layout, null,
                    new String[] {ExternalDatabase.getHeadwordColumnName()},
                    new int[] {android.R.id.text1},
                    0
                    );
    adapter.setFilterQueryProvider(
            new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    return mDatabase.getFilterCursor(mDictId, constraint.toString());
                }
            }
    );

    adapter.setCursorToStringConverter(
            new SimpleCursorAdapter.CursorToStringConverter() {
                @Override
                public CharSequence convertToString(Cursor cursor) {
                    return cursor.getString(1);
                }
            }
    );

    return adapter;
}
 
Example 6
Source File: MainActivity.java    From Open-Source-Android-Weather-App with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    // Initializations
    drawerLayout = findViewById(R.id.drawer_layout);
    navigationView = findViewById(R.id.nav_view);
    toolbar = findViewById(R.id.toolbar_main);

    // Sets the Toolbar to act as the ActionBar for this Activity
    setSupportActionBar(toolbar);

    // Disable title (There is a textView instead of title, so we can skip the title)
    Objects.requireNonNull(getSupportActionBar()).setDisplayShowTitleEnabled(false);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white);
    }


    cityCountryName = sharedPreferences.getString(CITY_COUNTRY_NAME, "");
    actvCityCountryName.setText(cityCountryName);


    if (database.isOpen()) {
        checkDatabaseState();
    } else {
        database = databaseHelper.getReadableDatabase();
        checkDatabaseState();
    }

    // Create a SimpleCursorAdapter for the State Name field.
    mAdapter = new SimpleCursorAdapter(this,
            R.layout.dropdown_text,
            null,
            new String[]{CITY_COUNTRY_NAME},
            new int[]{R.id.text}, 0);
    mAdapter.setFilterQueryProvider(constraint -> {
        if (constraint != null) {
            if (constraint.length() >= 3 && !TextUtils.isEmpty(constraint)) {
                Bundle bundle = new Bundle();
                String query = charArrayUpperCaser(constraint);
                bundle.putString(CITY_ARGS, query);
                getLoaderManager().restartLoader(0, bundle, MainActivity.this).forceLoad();
            }
        }
        return null;
    });

    // Set an OnItemClickListener, to update dependent fields when
    // a choice is made in the AutoCompleteTextView.
    actvCityCountryName.setOnItemClickListener((listView, view, position, id) -> {
        // Get the cursor, positioned to the corresponding row in the
        // result set
        Cursor cursor = (Cursor) listView.getItemAtPosition(position);

        // Get the state's capital from this row in the database.
        cityCountryName = cursor.getString(cursor.getColumnIndexOrThrow(CITY_COUNTRY_NAME));

        // Update the parent class's TextView
        actvCityCountryName.setText(cityCountryName);

        requestWeather();
        hideKeyboard();
    });

    actvCityCountryName.setAdapter(mAdapter);

    actionBarDrawerToggle = new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    // Activate navigation drawer's listener
    activateDrawerListener();
}