如何在textView中显示字符串的子字符串 [英] how to display substring of a string in textView
本文介绍了如何在textView中显示字符串的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取要从editText显示到textView的字符串的子字符串.我使用addTextChangedListener到edittext来执行此操作
在这种方法中,我尝试从edittext获取一个子字符串,以在运行该应用程序时显示在textView中.
i am trying to get a substring of a string to be displayed from an editText to a textView. i used addTextChangedListener to the edittext to perform this operation
in this method i am trying to get a substring from the edittext to be shown in the textView on running the app nothing happens.
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
TextView gtin = (TextView) findViewById(R.id.textView2);
String sgtin=gtin.getText().toString();
sgtin.substring(0,7);
gtin.setText(sgtin);
}
我在哪里可能出了错.需要指导
where have i possible gone wrong. need guidence
推荐答案
Java的substring()
返回一个字符串: ^ ]
所以你应该:
Java''ssubstring()
returns a string : http://www.tutorialspoint.com/java/java_string_substring.htm[^]
so you should :
String str = sgtin.substring(0,7);
gtin.setText(str);
这篇关于如何在textView中显示字符串的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文