事件上的EditText
我有一个EditText上的名字说EID ..now我要的是只要用户输入的EID值..an另一个EditText上说,OID现在OID应自动生成它的价值出EID输入值的..所以这事件我应该使用上面要执行的任务..
plz帮助我在android的非常新的
I have one edittext name say eid ..now what i want is as soon as user enter eid value ..an another edittext say "oid" now oid should automatically generate it's value out of the value entered in eid ..so which event should i use to perform above task.. plz help i am very new in android
您可以编辑文本使用textWatcher,它会在编辑文本的种种变化,并触发相应的功能。
You can use textWatcher on Edit Text, it gets all the changes in Edit Text, and triggers appropriate functions.
eid.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void afterTextChanged(Editable s) {
// set oid value now
oid.setText(eid.getText().toString());
}
});
每当文本将改变开斋节的方法afterTextChanged将被调用的,它会设定值也OID
Whenever the text will change of "eid" method afterTextChanged will be called and it will set the value of oid also.