How to know when a user is done typing?

397 Views Asked by At

In Android Studio, I want to make a program where a TextView changes to an EditView when clicked. After the user is finished typing, I want the EditText to then change back to a TextView which shows the value that was entered.

How do I do this? This is what I have so far:

loc > TextView, 
edit_loc > EditText

loc.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        loc.setVisibility(View.GONE);
        edit_loc.setVisibility(View.VISIBLE);
    }
});
2

There are 2 best solutions below

0
Amit pandey On

You can you simple edit text view and set it clickable false when user complete the typing .. for know when user is typing or not you use this code:

 editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        //when user is typing
        }

        @Override
        public void afterTextChanged(Editable editable) {
         // after user complete typing
        }
    });
0
BeNYaMiN On

regarding @amit-pandey, it's not the complete solution because after each typing the TextWatcher being called

check this link, it is better solution but it's not the best

https://stackoverflow.com/a/28625726/12177115