【发布时间】:2012-05-08 06:04:08
【问题描述】:
我正在制作一个基于问题和答案的应用,并且答案由用户输入并且必须准确。如何设置编辑文本以显示用户提供的答案有效,如果有效,我希望出现一个带有按钮的对话框继续并重试!
【问题讨论】:
-
您所要求的或多或少是对 java/android 的基本了解。请进一步研究
标签: java android android-emulator
我正在制作一个基于问题和答案的应用,并且答案由用户输入并且必须准确。如何设置编辑文本以显示用户提供的答案有效,如果有效,我希望出现一个带有按钮的对话框继续并重试!
【问题讨论】:
标签: java android android-emulator
您使用TextWatcher 来检查用户输入的答案是否有效。as
mEditText = (EditText)findViewById(R.id.ET);
mEditText.addTextChangedListener(mTextWatcher);
TextWatcher mTextWatcher = new TextWatcher() {
private CharSequence temp;
@Override
public void beforeTextChanged(CharSequence s, int arg1, int arg2,
int arg3) {
temp = s;
}
@Override
public void onTextChanged(CharSequence s, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable s) {
//CHECK HERE if answer is valid or not
}
};
【讨论】:
最好的办法是使用正则表达式模式,并确保文本框中的文本与该模式匹配。 Here's a good piece of documentation that I used to do this.
【讨论】: