- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我知道如何将整数值转化为字符串
String s = st.getText().toString(0;
但我的问题是我们将如何取一个字符...假设 textView txt1 的值 = 'A' 那么我们如何将值取为字符串 str1..
String str1 = txt1.getText().toString();
是否正确……?
最佳答案
TextView.getText() 返回 java.lang.CharSequence
,理想情况下,您应该能够应用 toString()
来获取 String 值。但是,然而,
来自 CharSequence
java doc
This interface does not refine the general contracts of the equals and hashCode methods. The result of comparing two objects that implement CharSequence is therefore, in general, undefined. Each object may be implemented by a different class, and there is no guarantee that each class will be capable of testing its instances for equality with those of the other. It is therefore inappropriate to use arbitrary CharSequence instances as elements in a set or as keys in a map.
CharSequence 是一个接口(interface)(尽管 toString() 显示为已声明),只要 CharSequence 实现者正确完成了他们的工作,它就应该可以工作。为避免任何意外,您可以尝试不同的方法
final StringBuilder sb = new StringBuilder(charSequence.length());
sb.append(charSequence);
return sb.toString();
关于java - Android 如何从 TextView 获取一个字符串到一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20511573/
我是一名优秀的程序员,十分优秀!