是否可以使用类似
的方法隐藏editText中的部分字符串editText.hide(int start, int finish);
因此在显示中我无法读取字符串的隐藏部分,但如果我在代码中使用editText.getText()
之类的方法,它将包含隐藏的字符串?
答案 0 :(得分:3)
您可以执行以下操作:
String wholeString = editText.getText().toString();
editText.setText(editText.getText().toString().substring(int start, int end));
其中start和end是您希望字符串开始并以您设置的位置结束的整数。
所以现在你在隐藏之前就拥有了整个字符串。此外,如果您想隐藏editText中间的某个部分,您可以执行以下操作:
editText.setText(editText.getText().toString().substring(0, 20) + editText.getText().toString().substring(25, 30));
您可以使用许多字符串设置editText文本。这将隐藏字符串从第21位到第25位。您必须根据需要对其进行修改。
您可能还需要知道名为lastIndexOf的字符串的方法(" Some Text")
示例:强>
//You have a string called example.
String example = "Android development is fun and nice."
String cutExample = example.substring(example.lastIndexOf("is") +3, example.lastIndexOf(".");
结果将是:"fun and nice"
。
因此lastIndexOf()
将返回已定义字符串的位置。
用我写的东西测试。希望有所帮助。