I implemented a custom ArrayAdapter to manage my data and show it in a ListView. This is the code of my custom adapter:
private class ViewHolder{
User user;
CheckBox check;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder=new ViewHolder();
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
User c = getItem(position);
if(convertView==null)
convertView=new userCheckableRow(getContext(),c.getChecked());
CheckBox name = (CheckBox)convertView.findViewById(R.id.userCheckBox);
name.setText(c.getName());
holder.user=c;
holder.check=name;
name.setChecked(holder.user.getChecked());
convertView.setTag(holder);
name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ViewHolder holder=(ViewHolder)((View)v.getParent().getParent()).getTag();
CheckBox ck=holder.check;
User c=(User) holder.user;
c.setChecked(ck.isChecked());
}
});
return convertView;
}
In my activity the user fills some fields and check some checkboxes; when he check them and then open/close keyboard to continue filling other fields, then the checkbox status is lost and these become all unchecked.
What I tried (and didn't work):
Set an OnFocusChangedListener to all EditText fields to intercept when they get focus;
Set an OnKeyListener to all EditText fields to intercept KEYCODE_BACK event;
Implement onBackPressed();
Implement a GlobalLayoutListener (How to check visibility of software keyboard in Android?) to intercept when keyboard is open, but with this code my checkboxes where unclickable because of continuous refreshing list;
Implement onConfigurationChanged() to listen to keyboardHides|screenResize , but this callback event can intercept only hard keyboard and however didn't work;
How can I manage this situation?