'Android Edit Text Focus Gone after input things in expandable list view
I have problem with the edit text. I have edit text inside child view for each group, and I can add the new group dynamically, when I key in the edit text for the groups that can fit in the screen initially, the focus is still pointing at the edit text, but when I click edit text to key in for those group that I need to scroll down, after I key in any first character, the edit text focus suddenly gone and point randomly How can this happen? I hope the picture is enough for you to understand. My adapter code:
@Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.personal_loan_list_group, null);
TextView titleText = (TextView) convertView.findViewById(R.id.lblListHeader);
Button deleteBtn = (Button) convertView.findViewById(R.id.deleteBtn);
titleText.setText("Group" + " " + (groupPosition+1));
deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
customer.removePersonalLoan(groupPosition);
notifyDataSetChanged();
}
});
return convertView;
}
@Override
public View getRealChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.personal_loan_list_item, null);
final CustomEditText installmentText = (CustomEditText) convertView.findViewById(R.id.installmentET);
installmentText.setTag("amount");
installmentText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
try {
installmentText.removeTextChangedListener(this);
installmentText.setText("999");
installmentText.addTextChangedListener(this);
} catch (Exception ex) {
ex.printStackTrace();
installmentText.addTextChangedListener(this);
}
}
});
return convertView;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|