Android setError ("error") 在 Textview 中不起作用

标签 android error-handling popup textview

我们可以在 Edittext 中成功设置错误,但在 textview 中设置失败。有什么问题吗?? 我试过了

((TextView) findViewById(R.id.df)).requestFocus();
((TextView) findViewById(R.id.df)).setSelected(true);
((TextView) findViewById(R.id.df)).setError("akjshbd");

但我没有弹出错误消息。

Textview Error

最佳答案

默认 TextView 不可聚焦。所以,你需要设置 android:focusable="true"android:focusableInTouchMode="true"

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:text="@string/hello_world" />

而且不需要设置 setSelected(true)。

((TextView) findViewById(R.id.df)).requestFocus();
((TextView) findViewById(R.id.df)).setError("akjshbd");

关于Android setError ("error") 在 Textview 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13508270/

相关文章:

haskell - 按错误类型参数化部分函数

python - 为什么从 Twitter-api 返回数据时有时会出现 python "KeyError:"错误,而其他时候则不会出现?

java - 如何正确处理来自 close() 的 IOException

android - 如果已执行,则禁用一个按钮

android - 有没有办法让每个 Activity 只有一个实例?

Android 可绘制资源在调试文件夹中创建?

android-如何扩展FragmentActivity和actionbaractivity

java - 点击编辑文本android时出错

blackberry - 黑莓上弹出窗口的白色边框

vb.net - 填充/大小/边距,当使用 ToolstripControlHost 作为弹出控件时