How do I focus on the counter?

I have a spinner and an edittext and I want if the spinner is selected the focus can be set in the edittext. I'm already trying but not going to work, how do I fix this?

This is my code:

edkontak1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if(actionId== EditorInfo.IME_ACTION_NEXT) {
                    sembunyikanKeyboard();
                    v.clearFocus();
                    spinnerkontak1.requestFocus();
                    spinnerkontak1.performClick();
                }
                return true;
            }
        });

 spinnerkontak1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String jeniskontak1 = spinnerkontak1.getSelectedItem().toString();
                if(jeniskontak1.equals("--")){
                    edkontak1.setText("");
                    edkontak1.setEnabled(false);
                    tkontak2.setVisibility(View.GONE);
                    tkontak3.setVisibility(View.GONE);
                    tkontak4.setVisibility(View.GONE);
                    tkontak5.setVisibility(View.GONE);
                }
                else{
                    edkontak1.setEnabled(true);
                    tkontak2.setVisibility(View.VISIBLE);
                    spinnerkontak1.setFocusable(true);
                    spinnerkontak1.setFocusableInTouchMode(true);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

private void sembunyikanKeyboard() {
        InputMethodManager inputmanaget = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanaget.hideSoftInputFromInputMethod(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }

      

Thanks in advance.

+3


source to share


2 answers


I think you should implement a query focusing method edkontak1.requestFocus();



0


source


What you did is correct. But you must add this line as well.



spinnerkontak1.setFocusable(true);

      

0


source







All Articles