Listview search with custom itemView

Asked

Viewed 88 times

0

I have a listView which has two text fields (nome and local) which are removed from an object Empresa.

The examples spread on the Internet only show search in listViews normal with only one string. How do I make for the search search in the text box nome within the itemView?

itemView que é carregada na listView

Code to search in listView of Strings:

   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.menu_item_search).getActionView();

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setOnQueryTextListener(this);
        return true;
    }

    @Override
    public boolean onQueryTextChange(String newText)
    {
        // this is your adapter that will be filtered
        if (TextUtils.isEmpty(newText))
        {
            list.clearTextFilter();
        }
        else
        {
            list.setFilterText(newText);
        }
        return true;
    }
    private class MyListAdapter extends ArrayAdapter<Empresa> {
        public MyListAdapter() {
            super(Main.this, R.layout.item_view, empresaList);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View itemView = convertView;

            if (itemView == null)
                itemView = getLayoutInflater().inflate(R.layout.item_view, parent, false);

            //acha empresa
            Empresa currentEmpresa = empresaList.get(position);

            //preenche lista

            TextView makeTxtEmpresa = (TextView) itemView.findViewById(R.id.item_txtNome);
            makeTxtEmpresa.setText(currentEmpresa.getNome());

            TextView makeTxtLocal = (TextView) itemView.findViewById(R.id.item_txtLocal);
            makeTxtLocal.setText(currentEmpresa.getLocal());

            return itemView;
        }
    }
  • What is the class of the variable list?

  • to fill the list have a private class that has been posted now

  • names are in private class

  • 1

    Why don’t you use the Filter in the Adapter? In this tutorial you have a step-by-step to implement one: http://www.survivingwithandroid.com/2012/10/android-listview-custom-filter-and.html.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.