2012-01-17 19 views

答えて

2

私が書いたアプリではこれを行う必要がありました。このサンプルでは、​​EditTextが空であるかどうかを確認し、空の場合はTextWatcherを作成します。それをチェックアウト:

// highlight any unfilled boxes 
final EditText text = (EditText) activity.findViewById(id); 
String data = text.getText().toString(); 
if (data.length() == 0) // 
{ 
    final Drawable oldBackground = activity.findViewById(id).getBackground(); 
    text.setBackgroundColor(Color.YELLOW); 
    text.addTextChangedListener(new TextWatcher() // 
    { 
     @Override 
     public void afterTextChanged(Editable s) // 
     { 
      text.setBackgroundDrawable(oldBackground); 
     } 

     @Override 
     public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) 
     { } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) 
     { } 
    }); 
} 

これは役に立ちます。

+0

ありがとう、それは仕事をしました。私は編集する前に参照を取得するためにgetBackgroundを使用し、リセットするために背景をその参照値に設定しました。 –

+0

@StefanDunn優秀!お役に立てて嬉しいです。 – Codeman

関連する問題