Displaying Error Hints in Forms on Android
Displaying error messages in forms on Android is really simple. Most widgets have a setError(CharSequence text)
method that can be used to indicate problems.
Say you have a form where you have to enter a product. Now while entering more data into the form the app might check the product number and some backend service might say, that the number is invalid. In this case a quick feedback would be nice. That's exactly what can be done with this method:
The setError()
method is only available for widgets that extend TextView
. But gladly all relevant Widgets for error messages do inherit from TextView
: EditText
, AutoCompleteTextView
, CheckBox
and RadioButton
(well, the hierarchy is weird, but never mind).
But there is one problem with using this approach. The message text is only visible when the view has the focus. Otherwise Android only displays the red marker. Try setting the focus on a touch screen with a radio button or a check box. Good luck to you. If you have a keyboard, trackball or so on, this is okay. But for most devices the necessity to focus is bound to fail. I would have preferred if the exclamation mark would have been clickable. Of course you can add a click listener and focus yourself, but this kind of defeats the purpose of this approach.
On the other hand this might not be that bad, since check boxes should only rarely fail a check and radio buttons in my opinion should never be allowed to do so. For check boxes a shopping app comes to mind where you must tick a check box to agree to some conditions before being able to proceed.
Then there is also the oddity that for EditText
fields the error hint disappears as soon as the field has lost its focus. In my opinion the hint should only disappear when the value has changed.
Even despite the mentioned problems you should add a setError()
method whenever you create you own widgets. And you should not stray too far from the standard design and usage patterns for displaying problems in your apps. As always I would recommend to stay close to the platform but adopt to your needs.
相關推薦
Displaying Error Hints in Forms on Android
Displaying error messages in forms on Android is really simple. Most widgets have a setError(CharSequence text) metho
In-app purchases on Android: new and upcoming
In-app purchases on Android: new and upcomingA closer look at the I/O 2018 announcementsGoogle I/O 2018 is just behind us, but it brought a lot of news whe
[PWA] Add Push Notifications to a PWA with React in Chrome and on Android
On Android and in Chrome (but not on iOS), it's possible to send push notifications with a PWA. We'll start by asking the user for permission to send them
Troubleshoot Courier Fetch Error in Kibana on Amazon ES
Use one or more of the following methods to resolve the courier fetch error: Consider resizing your cluster Confirm that
Weird error message in Android's MergeCursor
For an app I am working on I needed a MergeCursor to use search in a meaningful way. I needed to use two combine two
android studio 不能生成apk:Gradle build finished with 1 error(s) in 5 sec Unexpected error Local path do
大概原因是sdk版本過高無法自動生成apk(ps:無法生成還弄那麼高版本也是醉了); 解決辦法是:先將android studio 關閉,找一個低版本的sdk,將sdk中的tools檔案複製; 將android stu
android studio編譯報錯Gradle build finished with 100 error(s) in 14s 629ms
這兩天開始接觸android studio,發現這工具還是有很多問題,經常有版本不匹配的問題,今天就遇到了一個 Gradle build finished with 100 error(s) in 14s 629ms。無法編譯生成apk,最後查詢資料,發現是bui
Android--Gradle build finished with 232 error(s) in 1m 43s
Android–Gradle build finished with 232 error(s) in 1m 43s What is this?(這是啥?) 這些很多可能性是我們在Android 的開發過程中使用了過時的javaAPI,或者不太規範的程式設
php-fpm啟動報錯:libgearman.so.8: No such file or directory in Unknown on line 0
php 報錯 php-fpm 從一臺服務器上拷貝php-fpm程序到另一臺後啟動提示錯誤:/etc/init.d/php-fpm-5.4 start Starting php-fpm [27-Jul-2017 11:31:39] NOTICE: PHP message: PHP Warning:
Ubuntu 16.04升級4.7.0內核後導致Compiz奔潰,問題:compiz[4852]: segfault at 48 ip 00007f88cae087f0 sp 00007ffce354c268 error 4 in libscale.so
conf bsp alt get onf 桌面 支持 png style 由於硬件的驅動支持問題,升級4.7.0的內核主要是為了能使用Intel HD Graphics 630驅動,但是也出現了相關問題,比如Compiz的特效導致桌面上如果有多個相同程序啟動,然後再次點擊時
導入項目的時候報錯Error:Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha7
原因 自己 進行 ack class rain 選擇 and clas 問題描述 今天在導入項目的時候報錯: Error:Could not find com.android.support.constraint:constraint-layout:1.0.0-alph
Xcode Error returned in reply: Connection invalid
一個 rep too mman log ror eply cnblogs command 當電腦上有Xcode兩個版本是使用其中的某一個的Simulator時出現了這樣的報錯 在Preference->Location->Command Line Too
remount issue on android 7.0
n) 重新 tar 版本 all vfat art memmove html http://blog.chinaunix.net/uid-23141914-id-5754416.html 最近在新版本的android 7.0上,發現filesystem的remount老是報
NET Core 2.0 in Docker on Windows Containers
交互式 就是 point 站點 -c 系統默認 而且 正在 expose 安裝Docker for Windows https://store.docker.com/editions/community/docker-ce-desktop-windows 要想將一個ASP
Error occurred in deployment step ‘Retract Solution‘: xxx 無法反序列化,因為它沒有公共的默認構造函數
rsh chang str visual 原來 custom change family deploy 一.環境:SharePoint 2016 + Visual Studio 2015, 二.錯誤描述: 錯誤1:幫朋友寫個計時器Demo,部署位置GAC,來回部署幾次後
[Selenium+Java] SSL Certificate Error Handling in Selenium
abi ges git ssl cor bus cti inter rri Original URL: https://www.guru99.com/ssl-certificate-error-handling-selenium.html SSL Certificat
Cannot debug in IntellijIdea on Linux
int switch nat info png col ima dea TE OS: Deepin LinuxIDE: Intellij IdeaProject: SpringBoot based maven project Issue: cannot debug in I
php5.6,Ajax報錯,Warning: Cannot modify header information - headers already sent in Unknown on line 0
ont line span use -s nbsp ati bsp data php5.6ajax報錯 Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be r
Error:Failed to resolve: com.android.support:appcompat-v7
.com ppc com color mil spa err family clas repositories { maven { url "https://maven.google.com" } } Error
上傳文件報錯:Warning: POST Content-Length of 9443117 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
The lin clas php 但是 exce 小文件 情況 lan 只需在php.ini中設置: upload_max_filesize = 1000M; post_max_size = 1000M;還有一種情況就是小文件可以上傳成功,但是大文件上傳,$_FILES