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?

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?– Wakim
to fill the list have a private class that has been posted now
– Lucas Bertollo
names are in private class
– Lucas Bertollo
Why don’t you use the
Filterin theAdapter? In this tutorial you have a step-by-step to implement one: http://www.survivingwithandroid.com/2012/10/android-listview-custom-filter-and.html.– Wakim