Example usage for android.widget Filterable getFilter

List of usage examples for android.widget Filterable getFilter

Introduction

In this page you can find the example usage for android.widget Filterable getFilter.

Prototype

Filter getFilter();

Source Link

Document

Returns a filter that can be used to constrain data with a filtering pattern.

This method is usually implemented by android.widget.Adapter classes.

Usage

From source file:com.btmura.android.reddit.app.MenuHelper.java

private static void showSortDialog(Context context, final Filterable filterable, int titleResId,
        int itemArrayResId) {
    new AlertDialog.Builder(context).setTitle(titleResId)
            .setSingleChoiceItems(itemArrayResId, filterable.getFilter(), new OnClickListener() {
                @Override/*from   ww w .j  a  va  2s.  c o m*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    filterable.setFilter(which);
                }
            }).show();
}

From source file:com.sababado.support.v4.app.SearchableSupportListFragment.java

@Override
public void onTextChanged(CharSequence s) {
    // Make sure the adapter exists
    ListAdapter adapter;//from w  w  w.j  a  v a2 s . co  m
    if (getListView() == null || (adapter = getListView().getAdapter()) == null || s == null)
        return;
    //if adapter is filterable type then call ontextchanged
    if (adapter instanceof Filterable) {
        Filterable fAdapter = (Filterable) adapter;
        // get the adapter's filter
        Filter filter = fAdapter.getFilter();
        // make sure the filter exists before filering.
        if (filter != null)
            filter.filter(s);
    }

}

From source file:org.gots.ui.HutActivity.java

protected void performSearch(final EditText filter) {
    if (clearFilter) {
        currentFilter = "";
        filter.setText(currentFilter);/*from   w  w w  .  j a v a 2s. co m*/
        clearFilter = false;
        findViewById(R.id.clearSearchFilter).setBackground(getResources().getDrawable(R.drawable.ic_search));
    } else {
        currentFilter = filter.getText().toString();
        clearFilter = true;
        findViewById(R.id.clearSearchFilter)
                .setBackground(getResources().getDrawable(R.drawable.ic_menu_close_clear_cancel));
    }

    Fragment fragment = (Fragment) getSupportFragmentManager()
            .findFragmentByTag("android:switcher:" + R.id.pager + ":" + mTabsAdapter.getCurrentItem());
    if (fragment.getArguments() != null
            && fragment.getArguments().getBoolean(VendorListActivity.FILTER_PARROT)) {
        Intent filterIntent = new Intent(VendorListActivity.BROADCAST_FILTER);
        filterIntent.putExtra(VendorListActivity.FILTER_VALUE, currentFilter);
        sendBroadcast(filterIntent);
    } else if (fragment instanceof VendorListActivity) {
        if (false) {
            Filterable fragFilter = (Filterable) ((VendorListActivity) fragment).getListAdapter();
            fragFilter.getFilter().filter(currentFilter.toString());
        } else {
            Fragment searchFragment = (Fragment) getSupportFragmentManager()
                    .findFragmentByTag("android:switcher:" + R.id.pager + ":" + (FRAGMENT_ID_CATALOG));
            searchFragment.getArguments().clear();
            searchFragment.getArguments().putString(VendorListActivity.FILTER_VALUE, currentFilter);
            searchFragment.onResume();
            mTabsAdapter.setCurrentItem(FRAGMENT_ID_CATALOG);
        }
    }
}