开发者

How to know textcompletion, edittext

开发者 https://www.devze.com 2023-03-28 15:35 出处:网络
I have a created an EditText. I 开发者_开发问答can know text change using TextChangedListener. But I have a problem that I have to show some message to the user when the user has finished writing. to

I have a created an EditText. I 开发者_开发问答can know text change using TextChangedListener. But I have a problem that I have to show some message to the user when the user has finished writing. to achieve this i am assuming that if the user is idle for 500 milliseconds that means the user has finished writing. How to achieve this? is there any better way to know text completion?

Thanks


in TextChangedListener you can start a timer and restart it each time onTextChangedListener() method is called. and set its time to be 500milliSeconds. and when timer ends you can show your message.

**Update:**

when i say Timer use CountDownTimer which has onFinish() method which you can override and do your stuff...

and also if you have multiple views then you can use onFocusChangedListener(), whose method is called once user jumps to next TextView, which is better approach too..


If you are trying to guess (rather than ensure) that the user is done typing, obviously you will have to use heuristics such as the one you suggested.

In case you want to ensure, you can rely on the fact that the user attempted to hide the keyboard. This can be determined by going through Android: which event fires when on screen keyboard appears?.

Obviously, you have nothing with you if the user has a device with a physical keyboard.

HTH,

Akshay


EditText should inherit onFocusChanged from TextView.

EditText myEditText = (EditText)findViewById(R.id.myEdittext);
myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener(){
    @Override
    public void onFocusChange(View v,boolean hasFocus){
        if (!hasFocus) {
            // do some work
        }
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消