Android - 处理来自setOnEditorActionListener的TextView

时间:2017-07-26 23:55:58

标签: android textview

我正在尝试更改附加到EditText(金额)的setOnEditorActionListener事件中的TextView(totacost)的值,但它不起作用。

x是一个对象,x.setAmount()x上改变x.totalcost值的方法,我需要在textview中设置x.totalcost的新值。

amount.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH ||
                    actionId == EditorInfo.IME_ACTION_DONE ||
                    event.getAction() == KeyEvent.ACTION_DOWN ||
                            event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {

                    x.setAmount(Integer.parseInt(v.getText().toString()));

                   totalcost.setText(""+x.totalcost)
                    return true; // consume.
            }

            return false;
        }
    });

0 个答案:

没有答案