我想问一下如何从可扩展列表视图中的特定组中获取子视图?
我尝试过使用getChildAt(1),但它总是返回子视图1(从组视图1)(蓝线和文本),当我尝试使用getChildAt(2)时会出现错误,指向将视图指向null引用。如何创建一个可以检测其组2并获取其子视图的循环?我希望你能理解我的问题。
现在,我只能使用getChildAt(1)获取组1子视图。我希望得到第2组儿童视图。我将做一个for循环,循环所有组并相应地更新其子视图。
提前致谢。
这是我的适配器获取子视图:
@Override
public View getChildView(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);
formatText(installmentText, groupPosition);
installmentText.addTextChangedListener(this);
} catch (Exception ex) {
ex.printStackTrace();
installmentText.addTextChangedListener(this);
}
}
});
return convertView;
}
用于在会话期间仅格式化文本的formattext方法,例如5000自动更改为5,000到货币值
在我的活动中,我使用了:
listView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
for(int count = 1; count < people.getLoan().size(); count++) {
if(hasFocus) {
if (count != lastGroupPos) {
View view = listView.getChildAt(1);
CustomEditText editTxt = (CustomEditText) view.findViewById(R.id.installmentET);
String toSplit = FormatConverterUtil.formatString(editTxt);
people.getLoan().get(count - 1).setAmount(toSplit.replace(",", ""));
}
}
}
}
});