繁体   English   中英

如何从EditText获取前10位数字,并在TextView中设置这些数字?

[英]How can I get the first 10 digits from EditText, and set this digits in a TextView?

我有一个字段填充EditText控件,它的数字: 475759403048575663648495004945757590
我可以用什么来从这个EditText中选择前10个数字:
然后,在TextView中插入数字4757594030

您可以将字符串子串到10个字符。

String s = somestring.substring(0,10);

所以这将返回前10个字符,现在你可以将值S放在你的控件中!

您可以将textwatcher放入edittext,然后在编辑编辑文本时进行计数,当您获得字符数(在这种情况下为10)时,您可以显示这些字符。

TextView textView = ....
edittext.addTextChangedListener(new TextWatcher(){

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) { }

    @Override
    public void afterTextChanged(Editable textVal) {
        String inputText = textVal.toString();
        if (inputText.length() == 10) {
             textView.setText(inputText);
        }
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM