android: limit of 10 characters per line TextView

前端 未结 3 763
情深已故
情深已故 2021-01-19 18:31

I read value from EditText and write it to TextView

editTitle1.addTextChangedListener(new TextWatcher() {
              public void afterTextChanged(Editable         


        
3条回答
  •  清酒与你
    2021-01-19 19:09

    Define a method that returns a string formatted to have 10 characters per line:

    public String getTenCharPerLineString(String text){
    
        String tenCharPerLineString = "";
        while (text.length() > 10) {
    
            String buffer = text.substring(0, 10);
            tenCharPerLineString = tenCharPerLineString + buffer + "/n";
            text = text.substring(10);
        }
    
        tenCharPerLineString = tenCharPerLineString + text.substring(0);
        return tenCharPerLineString;
    }
    

提交回复
热议问题