how to use getlinecount() in textview android

前端 未结 6 1733
忘掉有多难
忘掉有多难 2021-01-12 02:03

i want to know how many line in my text view. i already set mytextview text, then i want to get how many line it take in mytextview.

i use mytextview.getLineCount()

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-12 02:51

    You need to post method for fetching the lines counts. Here is the sample code

    imageCaption.setText("Text Here");
    imageCaption.post(new Runnable() {
    
        @Override
        public void run() {
    
            int lineCount    = imageCaption.getLineCount();
    
            Log.v("LINE_NUMBERS", lineCount+"");
        }
    });
    

提交回复
热议问题