如何在Android中检查字符串中的行数? [英] How to Check the number of lines in a String in Android?

查看:27
本文介绍了如何在Android中检查字符串中的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从要传递给测试视图的字符串中检查文本视图中的行数.我添加了 android:maxLines = "2".... 如果超过两个,我需要显示/隐藏视图....我怎样才能做到这一点?

I want to check the no of lines in my text view from the string I am going to pass to the test view. I have added android:maxLines = "2".... If it exceeds two i need to show/hide a view....How can I achieve this?

推荐答案

使用线程统计行数,

 textView.setText("Text Here");
    textView.post(new Runnable() {

        @Override
        public void run() {

            Log.v("Line count: ", textView.getLineCount()+"");
        }
    });

如果你想从 xml 限制 TextView 中的行数,那么使用 android:maxLines

If you want to limit the number of lines in TextView from xml then use android:maxLines

这篇关于如何在Android中检查字符串中的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆