gpt4 book ai didi

android - EditText 在 Expandable ListView 中滚动时失去值(value)

转载 作者:行者123 更新时间:2023-11-30 00:52:21 25 4
gpt4 key购买 nike

当我滚动可扩展的 listview 时,我在 bean child.setCompliance_newComments(finalHolder2.newComplianceComment.getText().toString()) 中保存了 edittext 值,所有值都被删除.如何保值保仓?
谁能建议如何保存 edittext 值?

public ComplianceListAdapter(Context context, ArrayList<ComplianceGroupData> datas){
this.context=context;
this.groupDatas=datas;


}
@Override
public int getGroupCount() {
return this.groupDatas.size();
}

@Override
public int getChildrenCount(int groupPosition) {
ArrayList<ComplianceChildData> ch=groupDatas.get(groupPosition).getChild();
return ch.size();
}

@Override
public Object getGroup(int groupPosition) {
return groupDatas.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<ComplianceChildData> datas=groupDatas.get(groupPosition).getChild();
return datas.get(childPosition);
}

@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}

@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}

@Override
public boolean hasStableIds() {
return false;
}


@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ComplianceGroupData group = (ComplianceGroupData) getGroup(groupPosition);
GroupViewHolder holder1 = null;
View view=convertView;
if (convertView == null){
LayoutInflater layoutInflater=(LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=layoutInflater.inflate(R.layout.compliance_group_row,null);
holder1 =new GroupViewHolder();
holder1.group=(TextView)view.findViewById(R.id.tv_header);
view.setTag(holder1);
}
else {
holder1 = (GroupViewHolder) view.getTag();
}
holder1.group.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
holder1.group.setText(group.getGroupName());

return view;
}

@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final ComplianceChildData child = (ComplianceChildData)getChild(groupPosition, childPosition);
ArrayList<ComplianceChildData> datas=groupDatas.get(groupPosition).getChild();
ChildViewHolder holder = null;
View view1 = convertView;
if (convertView==null){
LayoutInflater inflater=(LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view1=inflater.inflate(R.layout.compliance_child_row_layout,null);
holder = new ChildViewHolder();
holder.compliance = (TextView) view1.findViewById(R.id.tv_compliance_list);
holder.chk_compliance=(RadioGroup)view1.findViewById(R.id.rg_chk_compliance);
holder.complianceYes=(RadioButton)view1.findViewById(R.id.rb_compliance_yes);
holder.complianceNo=(RadioButton)view1.findViewById(R.id.rb__compliance_no);
holder.complianceNotApplicable=(RadioButton)view1.findViewById(R.id.rb_compliance_not_applicable);
holder.oldComplianceComment=(EditText)view1.findViewById(R.id.et_old_compliance_comment);
holder.newComplianceComment=(EditText)view1.findViewById(R.id.et_new_compliance_comment);
view1.setTag(holder);
}
else {
holder = (ChildViewHolder) view1.getTag();
}

holder.compliance.setText(child.getCompliance_name());
holder.oldComplianceComment.setText(child.getCompliance_comment());
holder.chk_compliance.setOnCheckedChangeListener(null);
holder.chk_compliance.clearCheck();

switch (child.getCompliance_check()) {
case "Yes":
holder.complianceYes.setChecked(true);
holder.oldComplianceComment.setVisibility(View.VISIBLE);
holder.newComplianceComment.setVisibility(View.VISIBLE);

break;
case "No":
holder.complianceNo.setChecked(true);
holder.oldComplianceComment.setVisibility(View.VISIBLE);
holder.newComplianceComment.setVisibility(View.VISIBLE);

break;
case "Not Applicable":
holder.complianceNotApplicable.setChecked(true);
holder.oldComplianceComment.setVisibility(View.VISIBLE);
holder.newComplianceComment.setVisibility(View.VISIBLE);

break;
default:
// holder.chk_compliance.clearCheck();
holder.oldComplianceComment.setVisibility(View.GONE);
holder.newComplianceComment.setVisibility(View.GONE);

break;
}
final ChildViewHolder finalHolder = holder;
holder.chk_compliance.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int childCount = group.getChildCount();
for (int x = 0; x < childCount; x++) {
RadioButton btn = (RadioButton) group.getChildAt(x);

if (btn.getId() == checkedId) {
child.setCompliance_check(btn.getText().toString());
finalHolder.oldComplianceComment.setVisibility(View.VISIBLE);
finalHolder.newComplianceComment.setVisibility(View.VISIBLE);
System.out.println("Adapter----->"+child.getCompliance_check());

}

}

}
});
final ChildViewHolder finalHolder2 = holder;
holder.newComplianceComment.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {
child.setCompliance_newComments(finalHolder2.newComplianceComment.getText().toString());
System.out.println("setcomment----->" + finalHolder2.newComplianceComment.getText().toString());
System.out.println("getcomment----->" + child.getCompliance_newComments());


}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {


}
});

return view1;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
private class ChildViewHolder {
TextView compliance;
RadioGroup chk_compliance;
EditText oldComplianceComment,newComplianceComment;
RadioButton complianceNo,complianceYes,complianceNotApplicable;

}
private class GroupViewHolder {
TextView group;
}

最佳答案

删除
if (convertView==null) {
} 别的 {
}
Group 和 Child。它适用于您的场景。

关于android - EditText 在 Expandable ListView 中滚动时失去值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40783012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com