Reputation: 31
I have an EditText. I want this edittext to always be in focus and writeable. How can I do this without touching it every time? Because barcode scanner machine sends data successive to this app.
anasayfa_barkod.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) &&
(i == KeyEvent.KEYCODE_ENTER)) {
adapter.clear();
adapter.notifyDataSetChanged();
geciciListeyeEkle();
listeyiYukle();
adapter.notifyDataSetChanged();
tutarYazdir();
if(anasayfa_verilenUcret.getText().length()>0){
try{
String ucret=anasayfa_verilenUcret.toString();
String paraustu=String.valueOf(Double.parseDouble(ucret)-gelenSatis);
anasayfa_paraustu.setText(paraustu);
}catch (NumberFormatException e){
e.printStackTrace();
}
}
anasayfa_barkod.requestFocus(); //not working
return true;
}
return false;
}
});
I tried a lot of method.but all of them is not working. I can set the keyboard is visible but cursor not on edittext.
Upvotes: 0
Views: 1212
Reputation: 31
I solved my problem with enter link description here
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if ( anasayfa_barkod!= null) {
anasayfa_barkod.requestFocus();
}
}
}, 1000);
Upvotes: 1
Reputation: 1
I think may I can help. Use this in onCreate method
editText.requestFocus();
it works for me.
Upvotes: 0
Reputation: 4123
If you are in activity add this in your onCreate method:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
if you are in fragment use this:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Upvotes: 0