當我滾動可展開的listview
時,我已經在bean中保存了edittext值所有的值都被刪除。如何保存價值和地位?
任何人都可以建議如何保存edittext
值?EditText在滾動Expandable ListView時丟失值
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;
}
}
將標記設置爲textview,然後再次在滾動上檢索標記。 –
你可以請簡單解釋一下。我把setTag和getTag來獲得價值嗎? – Babu
'final ChildViewHolder finalHolder = holder;'和'final ChildViewHolder finalHolder = holder;'。你應該擺脫那些無用的東西。他們將始終指向最後調用getGroupView的項目。 – greenapps