Android的发展:计数的EditText线条框TextChanged? [英] Android Development: Count EditText Lines on textChanged?

查看:196
本文介绍了Android的发展:计数的EditText线条框TextChanged?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能指望在一个EditText行数? 基本上在我的应用程序,我有行号,我想让他们在textchange更新(我已经有textchangelistener设置)。 这可能吗? :(

How can I count the number of lines in an EditText? Basically in my app I have line numbers and I wanted to make them update on textchange (I already have the textchangelistener set up). Is this possible? :(

谢谢, 亚历克斯!

推荐答案

行可以型动物:

  • 在可视行:换行文本数作为新行...
  • 列表项目:只有\ r线,\ n,即\ r \ñ

第一种情况(最简单):

First case (the easiest):

int nbLines = editText.getLineCount();

第二种情况:

Second case:

        int nbLines = 0;
        StringReader     sr = new StringReader(editText.getText().toString());
        LineNumberReader lnr = new LineNumberReader(sr);
        try { 
            while (lnr.readLine() != null){}
            nbLines = lnr.getLineNumber();
            lnr.close();
        } catch (IOException e) {
            nbLines = editText.getLineCount();
        } finally {
            sr.close();
        }

这篇关于Android的发展:计数的EditText线条框TextChanged?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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