Hello i need to put some text inside the searchView and focus/expand the searchView widget.
this is what i tried but it doesn't work. Only the keyboard is open.
Yes, I check the other solutions in the web
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_busqueda, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
searchView.setQuery("test",true);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener()
{
@Override
public boolean onQueryTextChange(String newText)
{
// this is your adapter that will be filtered
Log.d("dimar","on text chnge text: " + newText);
List<Producto> lista = new Select().from(Producto.class).execute();
List <Producto> lista2 = new ArrayList<Producto>();
for (int i=0;i<lista.size();i++)
{
if (lista.get(i).getNombre().contains(newText)||lista.get(i).getLocal_id().contains(newText))
{
lista2.add(lista.get(i));
}
}
AdaptadorCuentas adap = new AdaptadorCuentas(MainActivity.this,lista2);
listView.setAdapter(adap);
return true;
}
@Override
public boolean onQueryTextSubmit(String query)
{
// this is your adapter that will be filtered
Log.d("dimar", "on query submit: " + query);
return true;
}
};
searchView.setOnQueryTextListener(textChangeListener);
return super.onCreateOptionsMenu(menu);
}