Android学习--小白易错--TextView

TextView的setText()方法在设值时,要注意,形参的类型。下面是对一个用于显示数值的TextView设值时,没有转成String类型,导致出错。

public final void setText (int resid)
Since: API Level 1

public final void setText (int resid, TextView.BufferType type)
Since: API Level 1

public final void setText (char[] text, int start, int len)
Since: 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 void setText (CharSequence text, TextView.BufferType type)
Since: API Level 1

Sets the text that this TextView is to display (see setText(CharSequence)) and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.

Related XML Attributes
public final void setText (CharSequence text)
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.

11-05 10:53:43.780: E/AndroidRuntime(21035): FATAL EXCEPTION: main
11-05 10:53:43.780: E/AndroidRuntime(21035): android.content.res.Resources$NotFoundException: String resource ID #0x191b
11-05 10:53:43.780: E/AndroidRuntime(21035): at android.content.res.Resources.getText(Resources.java:252)
11-05 10:53:43.780: E/AndroidRuntime(21035): at android.content.res.MiuiResources.getText(MiuiResources.java:125)
11-05 10:53:43.780: E/AndroidRuntime(21035): at android.widget.TextView.setText(TextView.java:3642)
11-05 10:53:43.780: E/AndroidRuntime(21035): at com.example.neteasedemo.MainActivity$MyAdapter.getView(MainActivity.java:186)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值