简体   繁体   English

在每行新行的开头添加文本

[英]Add Text at the Beginning of each new Line EditText

I am trying to get the text inout by the user in EditText,so I got the new text and detected the new line in it but I want to add a text at the begining of each new line..How to do that ? 我试图让用户在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


                        }
                    }

You can try this: 您可以尝试以下方法:

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);


                    }
                }

Reference: Android - Edit Text 参考: Android-编辑文字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM