android: limit of 10 characters per line TextView

前端 未结 3 764
情深已故
情深已故 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:01

    I edited the answer given by ramaral he used wrong escape sequence

    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;
    }
    
    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
  • 2021-01-19 19:11

    Add the following 2 attributes to the TextView definition:

    android:singleLine="false"  
    android:maxems="10"
    
    0 讨论(0)
提交回复
热议问题