C
C
cepprice2019-11-08 15:27:38
Java
cepprice, 2019-11-08 15:27:38

Why is OnFocusChange not working?

public class EditNoteActivity extends AppCompatActivity implements View.OnFocusChangeListener {

    private String TAG = "EditNote";

    EditText edtNoteTitle;
    

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_note);

        edtNoteTitle = findViewById(R.id.edt_note_title);

        edtNoteTitle.setOnFocusChangeListener((v, f) -> {
            Log.d(TAG, "1"); // Выводится
        });

    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (v.getId() == R.id.edt_note_title) {
            Log.d(TAG, "2"); // Не выводится
        }
    }
}

I click on the EditText , "1" is logged, but "2" is not.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AndroidDev2015, 2019-11-08
@cepprice

You have set listener to "1" only.
If you want to call "2" write edtNoteTitle.setOnFocusChangeListener(this)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question