【android】入力ミスがあるとeditTextが伸びて警告が表示される処理をむりくり手作りで作ってみた

フォームで項目を書いていて入力に抜けがあった場合、「正しい値を入力してください」や

「文字がぬけています」などの警告がでてくるアレについてです。

androidでは以下のように書くことが出来ます。

 

</pre>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:paddingStart="10dp"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/tel"
android:textSize="@dimen/signupPage_nametext_size"
android:layout_marginTop="22dp"
android:layout_marginStart="100dp"
android:layout_marginEnd="25dp"
android:background="@drawable/shape_edittext"
android:maxLength="16"
android:inputType="text"
tools:ignore="SpUsage" />
<ImageView
android:id="@+id/tel_blok_line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingBottom="28dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:layout_marginTop="62dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:visibility="visible"/>
</RelativeLayout>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_alert_messagebox"
android:paddingBottom="30dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:visibility="visible"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/warningTel"
android:text="@string/alert_tel"
android:layout_marginTop="2dp"
android:gravity="center"
android:textSize="14sp"
android:textColor="#FF3300"
android:visibility="visible"
android:typeface="serif"/>
</RelativeLayout>
<pre>

backgrondやテキストのところは適宜入れ替えてください。

デフォルトではvisibleになっていますが、java側でgoneに切り替えることができます。

車輪の再発明をやってしまった感はありますが、自分の知識の範囲ではこれまで。

>株式会社シーポイントラボ

株式会社シーポイントラボ

TEL:053-543-9889
営業時間:9:00~18:00(月〜金)
住所:〒432-8003
   静岡県浜松市中央区和地山3-1-7
   浜松イノベーションキューブ 315
※ご来社の際はインターホンで「316」をお呼びください

CTR IMG