我正在渲染我的数据库中的值并将这些值放在相应的 EditText 字段中,因此通常允许用户修改他们的保存数据。
我的页面上有一个保存按钮,默认情况下是禁用的。只有在真正修改了 EditText 字段时才应启用它。
与数据库值比较时,
- 如果编辑文本值更改 - 修改
- 如果 EditText 值已编辑但未更改(用户可以复制粘贴相同的值)- 未修改。
这是我的代码,
EditText text1 = (EditText) findViewById(R.id.text1);
EditText text2 = (EditText) findViewById(R.id.text2);
EditText text3 = (EditText) findViewById(R.id.text3);
EditText text4 = (EditText) findViewById(R.id.text4);
EditText text5 = (EditText) findViewById(R.id.text5);
ArrayList<EditText> editTextList = new ArrayList();
editTextList.add(text1);
editTextList.add(text2);
editTextList.add(text3);
editTextList.add(text4);
editTextList.add(text5);
for(EditText e : editTextList)
e.addTextChangedListener(textWatcher);
private TextWatcher textWatcher = new TextWatcher() {
public void afterTextChanged(Editable s){}
public void beforeTextChanged(CharSequence s, int start, int count, int
after) {}
public void onTextChanged(CharSequence s, int start, int before,int
count) {}
};
有没有办法将数据库值与 EditText 中的当前给定值进行比较?
笔记:
由于 TextWatcher 函数对所有 EditText 都是通用的,所以我想做一个通用的比较。