你如何得到它,以便编辑文本只接受文本,如果用户有一个K
进入开始
喜欢
答案 0 :(得分:1)
在android中,有一个用于文本更改的监听器:
EditText mEditText = (EditText) findViewById(R.id.my_edit_text);
//now you can add the listener here:
mEditText.addTextChangedListener(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) {
// here get the value entered by user and get the character
//at index 0;
String value = "what the user has entered".charAt(0)
//now use an if statement here to see if it is your required value (K); if not, set EditText to disabled - not active;
}
@Override
public void afterTextChanged(Editable s) {
}
});
我希望这有助于您开始使用!