【发布时间】:2015-03-26 10:43:54
【问题描述】:
我的程序中有一个编辑文本和一个评分栏。我正在检查用户在编辑文本中是否有超过 3 个字符,并且对于评分栏,它应该有大于 0.5 星的内容(基本上是为了检查他们是否至少点击了其中的任何一个)。
final EditText commentbox = (EditText)findViewById(R.id.comment);
final RatingBar rating = (RatingBar)findViewById(R.id.rating);
final Button feedbackbutton = (Button)findViewById(R.id.submit);
final TextWatcher watcher = new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(commentbox.length() >= 3 && rating.getNumStars() >=0.5){
feedbackbutton.setEnabled(true);
feedbackbutton.setBackgroundColor(Color.parseColor("#369742"));
} else {
feedbackbutton.setEnabled(false);
feedbackbutton.setBackgroundColor(Color.parseColor("#ffcacaca"));
}
}
};
commentbox.addTextChangedListener(watcher);
rating.setOnRatingBarChangeListener((this));
如您所见,它必须满足这些条件才能启用按钮并更改其背景颜色。但是,一旦我在编辑文本中写入超过 3 个字符,该按钮就会自动启用并更改其颜色。它不是在寻找评级栏条件。
谁能帮帮我
【问题讨论】:
标签: java android xml textwatcher ratingbar