Automatically click submit button and how to pass

2019-07-23 09:07发布

My idea, in app, there are two views, one is editText and another is submit button, when click editText, some pre-set characters will be pasted into the editText, and then click submit button to send these characters. For now, half work done is done. Pre-set characters can be pasted into editText field, but still need click submit button manually. so another half work is if or not when editText being filled, submit button will be clicked automatically. can I set submit button on soft keyboard clicked automatically when editText is being filled?

Another issue is in another app, submit button is being limited to click with specific time, maybe one second, still no idea about how to pass through this time limit. call system time and set up system time one second advanced? that can pass this time limit?

1条回答
劫难
2楼-- · 2019-07-23 09:39

You can use a TextWatcher to monitor the EditText for changes.

You can use a TextWatcher like so:

editText.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        submitButton.performClick();
    }
});

With a TextWatcher, you can respond to certain events related to the text entered into the EditText. With this example, I'm simulating a click on the Button after text has been changed.

查看更多
登录 后发表回答