我有几个 EditText 字段,我想用 setOnFocusChangeListener 将它们保存到 SQLiteDatabase。我是否必须为每个单独设置一个 onFocusChangeListener,或者是否有某种包罗万象的方法?(getActivity().findViewByID 因为这是一个片段)
final TextView txtName = (TextView)getActivity().findViewById(R.id.clientHeader);
final TextView txtCompany = (TextView)getActivity().findViewById(R.id.txtContactCompany);
final TextView txtPosition = (TextView)getActivity().findViewById(R.id.txtContactPosition);
txtName.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus) {
saveThisItem(txtClientID.getText().toString(), "name", txtName.getText().toString());
}
}
});
txtCompany.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus) {
saveThisItem(txtClientID.getText().toString(), "company", txtCompany.getText().toString());
}
}
});
txtPosition.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus) {
saveThisItem(txtClientID.getText().toString(), "position", txtPosition.getText().toString());
}
}
});
就像...有没有办法让 EditText 视图的 ArrayList < EditText >,为现有的 editTexts 分配一个指针(抱歉,不确定如何)并将 onFocusChangeListener 设置为整个数组列表?或者,甚至,遍历 ArrayList 并将 onFocusChangeListener 设置为每个成员?
或者一种检测任何 onFocusChangeListener 事件的方法,并将所有数据保存到数据库中,而不管事件发生在什么 EditText 上?