TextView.getText().toString() 与 TextView.toString()

TextView.getText().toString() vs TextView.toString()

这两种方法做同样的事情,但在大多数论坛上我看到第一种被使用而第二种几乎没有。第二种从 TextView 获取 String 的方法是错误的还是第一种方法比第二种方法有一些优势,因为它使用得更频繁?

textView.getText() returns 字符序列。要将 CharSequence 转换为 String,使用 toString() 方法。因此我们做textView.getText().toString()。此方法广泛用于从 TextView.

中获取字符串格式的文本 另一方面,

TextView.toString() returns TextView 对象的字符串表示,它在 TextView class 的 toString() 方法中定义。

举例说明:

假设我们有一个 TextView,其中 "Hello World" 作为显示在屏幕上的文本。

textViewobj.getText().toString() 将 return:

Hello World

其中 textViewObj.toString() 将 return 值类似于以下内容:

android.support.v7.widget.AppCompatTextView{58a835e V.ED..... ......ID 0,0-0,0 #7f0800a3 app:id/textView}

这是 TextView 的内存字符串表示。

TextView.getText().toString()--

给出字符串值,我们可以在 textView 小部件中直观地SEE

TextView.toString()--

给出string reference of the TextView object in the memory。这个值可以是这样的:-

   @2848&8berx   or,
   @89jccxyzsjjx