setOnFocusChangeListener を使用して SQLiteDatabase に保存したい EditText フィールドがいくつかあります。それぞれに 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 >を取得し、既存のeditTextにポインターを割り当て(申し訳ありませんが、方法はわかりません)、onFocusChangeListenerをarraylist全体に設定する方法はありますか?それとも、ArrayList を繰り返し処理し、onFocusChangeListener を各メンバーに設定しますか?
または、任意の onFocusChangeListener イベントを検出し、イベントが発生した EditText に関係なく、すべてのデータをデータベースに保存する方法はありますか?