Parent view is not a TextViewd的解决办法

本文详细解析了在Android开发过程中使用EditText组件时遇到的常见错误之一:将整数类型误作为视图ID传递给setText()方法导致的异常。文章通过实例演示了正确的使用方法,并提供了官方文档链接进行深入学习。此外,还介绍了如何安全地使用setText方法设置文本,以及一些相关XML属性的使用技巧。


一般是使用 EditText的 setText()时参数传错了,比如setText(111),安卓把int类型的参数视为 view 的 id,结果找不到这个资源,导致异常崩溃。


正确使用方法 setText(”111“)


官网地址:


http://developer.android.com/reference/android/widget/TextView.html#setText(int)


public final void setText (int resid)
Added in   API level 1

public final void setText (char[] text, int start, int len)
Added in   API level 1

Sets the TextView to display the specified slice of the specified char array. You must promise that you will not change the contents of the array except for right before another call to setText(), since the TextView has no way to know that the text has changed and that it needs to invalidate and re-layout.

public final void setText (int resid, TextView.BufferType type)
Added in   API level 1

public final void setText (CharSequence text)
Added in   API level 1

Sets the string value of the TextView. TextView does not accept HTML-like formatting, which you can do with text strings in XML resource files. To style your strings, attach android.text.style.* objects to a SpannableString, or see the Available Resource Types documentation for an example of setting formatted text in the XML resource file.

Related XML Attributes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值