在每个新行EditText

时间:2016-11-23 14:28:44

标签: java android

我试图让用户在EditText中输入文本,因此我获得了新文本并检测到了新行,但我想在每个新行的开头添加一个文本。如何做到这一点?

Ibold.addTextChangedListener( new TextWatcher(){
                    @Override
                    public void onTextChanged( CharSequence txt, int start, int before, int count ) {
                        if (-1 != bold.indexOf("\n") ){


                           //here I detected new line


                        }
                    }

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

Ibold.addTextChangedListener( new TextWatcher(){
                @Override
                public void onTextChanged( CharSequence txt, int start, int before, int count ) {
                    if (-1 != bold.indexOf("\n") ){


                       //here I detected new line
                        String editTextContent = Ibold.getText().toString();
                        editTextContent += "ADD YOUR TEXT HERE, IT WILL BE INSERTED AFTER THE LAST LINE BREAK";
                        Ibold.setText(editTextContent);


                    }
                }

参考:Android - Edit Text