我的视图中有 3 个 Edittexts 和 3 个微调器,每当任何 edittext 文本值发生变化或任何微调器选择发生变化时,我都必须进行 service cal ,我如何获得通知,例如 edittext 或微调器选择发生变化?
You need to add listeners to the EditTexts and Spinners.
For the EditTexts try this:
editText1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// your code here
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// your code here
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// your code here
}
});
And for the Spinners try this:
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// your code here
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
}
Have you checked the api documentation? All android views have pretty clear listener apis. EditText / TextView is no exception: addTextChangedListener
Spinners have: setOnItemSelectedListener
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.