1
How do I get focus on one EditText
but I’m still in trouble?
I’m making a ordering system, I have 3 EditText
(product, quantity and discount) and a button Add.
I need that when the user click the add button, the focus goes back to the product field, today the focus is going to a editText
of listView
(order items) that has just been added.
So if the user adds 30 products he has to scroll the screen up and put the focus on the product.
I’m using Android 4.1
Code (in the onclick
of the add button)
try{
validaProdutoLista(item, pedido.getListaItemPedido());
pedido.adicionaItens(item);
listViewItensPedidos.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, pedido.getListaItemPedido().size() * 50));
TabelaItensPedidoAdapter adapter = new TabelaItensPedidoAdapter(PedidoActivity.this, pedido.getListaItemPedido());
listViewItensPedidos.setAdapter(adapter);
adapter.notifyDataSetChanged();
Log.i(TAG, "Itens add "+pedido.getListaItemPedido().size());
codProduto.setText("");
codProduto.requestFocus(); //voltar o foco para o produto
}catch (MyException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
tries to use request Focus in xml
– Joannis
If I use requestFocus in xml, the focus already goes to the field as soon as it opens the screen, but that’s not what I need, I need it only when a product is added that the focus goes back to Edittext product.
– Alves Felipe
Just like you’re doing should work...
– Jorge B.
@Jorgeb. this is the bad of Android, what should work sometimes does not work depending on the version and the device... Maybe you have to see another way
– Wakim
Alves tries to make
codProduto.clearFocus();
before thecodProduto.requestFocus();
– Jorge B.
then Jorge, has not changed anything, the focus always goes to the listview editText that was added.
– Alves Felipe
If anyone has any other ideas, they are very welcome.. rs
– Alves Felipe
What is the name of editText of listview that is receiving the phocus?
– ramaral
@Alvesfelipe On the line with
codProduto.requestFocus();
change tocodProduto.requestFocus(FOCUS_UP, null);
and see what happens. and also create a Boolean var to see if the codProduct.requestFocus is returning true or false.– Olimon F.
ramaral, the name is itbProduct.
– Alves Felipe
Olimon, no good, the focus keeps going to the next field, but returns true in the codProduct.requestFocus
– Alves Felipe