0

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.

abtech
  • 31
  • 1
  • 6
  • `editText.requestFocus()` Possible duplicate of https://stackoverflow.com/questions/18295802/how-to-make-edittext-not-focused-when-creating-activity and https://stackoverflow.com/questions/14327412/set-focus-on-edittext – Lokesh Pandey Oct 16 '17 at 06:48
  • this is not working – abtech Oct 16 '17 at 06:49
  • show us your code this is not the way you should ask questions on SO better read https://stackoverflow.com/help/how-to-ask – Lokesh Pandey Oct 16 '17 at 06:50

3 Answers3

1

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);
abtech
  • 31
  • 1
  • 6
0

I think may I can help. Use this in onCreate method

editText.requestFocus();

it works for me.

haseeb
  • 1
  • 3
0

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);
FarshidABZ
  • 3,860
  • 4
  • 32
  • 63
  • try this: `getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT‌​_INPUT_STATE_ALWAYS_‌​VISIBLE);` `EditText.requestFocus()` `EditText.performClicked()` – FarshidABZ Oct 16 '17 at 07:16