开发者

how do i enter the value in one EditText and get answer in other EditText android

开发者 https://www.devze.com 2023-04-02 11:52 出处:网络
I have two EditText fields,whenever i enter the value in one editText,the other should display the answer for one calculation that taking the value of first editText,Iam unsure how to do this,thanks 开

I have two EditText fields,whenever i enter the value in one editText,the other should display the answer for one calculation that taking the value of first editText,Iam unsure how to do this,thanks 开发者_C百科in advance(android)


you can do this by using EditText's onKeyListener event, you can also show result when specific key is pressed


Use a TextWatcher and update the content of the target on each change.


The best method for this question is .addTextChangedListener()

you can use it by this code:

editText_1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
                try {
                    //Your Codes
                } catch (Exception e) {
                    // if editText_1 become null or "" 
                    editText_1.setText("0");

                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
0

精彩评论

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

关注公众号