2017-05-25 17 views
1

xmlで特定の値の定義済み入力を入力するにはどうすればよいですか?たとえば、私は120/80になることができる血圧を入力するユーザーを入力したいので、私は入力スラッシュが既に配置されている入力フィールドに入力するユーザーにしたいと思います。お知らせ下さい。 これは、あなたがこれもテキストウォッチャーを使用する必要があり、あなたは簡単なようにそれを行うにしたい場合は、私はそれに持っている最も近いが、このAndroid定義済み入力

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="3" 
      android:gravity="start" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="10dp" 
      android:orientation="horizontal"> 

     <android.support.design.widget.TextInputLayout 
       android:layout_weight="0.8" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

      <android.support.design.widget.TextInputEditText 
        android:id="@+id/patientBloodPressure1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:focusable="true" 
        android:imeOptions="actionNext" 
        android:maxLines="1" 
        android:textSize="14sp" /> 

     </android.support.design.widget.TextInputLayout> 

     <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.45" 
       android:layout_gravity="center_horizontal|center_vertical" 
       android:gravity="center" 
       android:padding="2dp" 
       android:text="@string/slash" 
       android:textSize="14sp" 
       android:textStyle="bold" /> 


     <android.support.design.widget.TextInputLayout 
       android:layout_weight="0.75" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

      <android.support.design.widget.TextInputEditText 
        android:id="@+id/patientBloodPressure2" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:focusable="true" 
        android:imeOptions="actionNext" 
        android:maxLines="1" 
        android:textSize="14sp" /> 

     </android.support.design.widget.TextInputLayout> 


    </LinearLayout> 
+0

私はそれを正しくしてください:スラッシュで区切られた2つの別々のフィールドに、ヒントではなくデフォルト値が入りたいとします。右? – gonczor

+0

正確ではないが、ヒントも機能することができます。私はちょうど上記がほしいと思う、より簡単な方法があるかどうか疑問に思う。 – sammyukavi

答えて

0

上にその長さを横断するときにいくつかのオプションがあります( - )

もセパレータを追加します。 最初にスラッシュの前に1つ、後に1つの編集テキストを組み合わせることができます。

2番目のオプションは、クレジットカードの有効期限とほぼ同じです日付

editText.addTextChangedListener(new TextWatcher() { 
@Override 
public void afterTextChanged(Editable s) { 
    // TODO Auto-generated method stub 
} 

@Override 
public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
    // TODO Auto-generated method stub 
} 

@Override 
public void onTextChanged(CharSequence s, int start, int before, int count) { 
    if (before == 1 && count == 2 && s.charAt(s.length()-1) != '/') { 
     editText.setText(editText.getText() += "/"; 
    } 
    if (editText.getText().toString().toCharArray().length < 3) { 
     editText.setText(editText.getText().toString().replace("/", "")); 
    } 
} 
}); 

そして最後に、このようなカスタマイズのEditText作成:TextWatcherを使用して https://github.com/woxingxiao/XEditText

0

ある

私が持っているもの

enter image description here

です実行時に値を検証するのに役立ちます。

あなたはtextwatcherなどであなたの検証を追加することができます:二つの部分に

分割文字列を、これらがあなたのそれぞれの値に属しているかいないことをint型の値をチェック。文字列は3

0

することは本当に難しいだろう。低血圧の人が80/50を入力する必要があるいくつかの最先端の症例では、この数字にを自動的に追加するために3桁の数字を使用することはできません。

android:hintを使用して、2つの別々のフィールドを使用することをお勧めします。いいえ

Blood Pressure (TextView Label) 
_____MAX_____/______MIN______ 
関連する問題