expandablelistview - Keep values of editText boxes into an expandable list view on Android -


i created expandable view contains edittext box under each group.

    public class expandableactivity extends appcompatactivity {          expandablelistadapter listadapter;         expandablelistview explistview;         list<string> listdataheader;         hashmap<string, list<string>> listdatachild;          @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_expandable);              explistview = (expandablelistview) findviewbyid(r.id.expandablelistview);             explistview.setdescendantfocusability(viewgroup.focus_after_descendants);              // preparing list data //custom function populates listdataheader , listdatachild             preparelistdata();               listadapter = new expandablelistadapter(this, listdataheader, listdatachild);             explistview.setadapter(listadapter); 

adapter code:

    public class expandablelistadapter extends baseexpandablelistadapter {          private context context;         private list<string> listdataheader;         private hashmap<string, list<string>> listdatachild;          public expandablelistadapter(context context, list<string> listdataheader,                                      hashmap<string, list<string>> listchilddata) {             this.context = context;             this.listdataheader = listdataheader;             this.listdatachild = listchilddata;         }           @override         public view getchildview(final int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) {             final string childtext = (string) getchild(groupposition, childposition);              if (convertview == null) {                 layoutinflater infalinflater = (layoutinflater) this.context.getsystemservice(context.layout_inflater_service);                 convertview = infalinflater.inflate(r.layout.e_list_item, null);             }              textview vw_text_sub = (textview) convertview.findviewbyid(r.id.esubt);             edittext vw_edit = (edittext) convertview.findviewbyid(r.id.eedit);              vw_text_sub.settext(childtext);              vw_edit.addtextchangedlistener(new textwatcher() {                  @override                 public void ontextchanged(charsequence arg0, int arg1, int arg2, int arg3) {                                     //store value?                 }                  @override                 public void beforetextchanged(charsequence arg0, int arg1, int arg2, int arg3) {                 }                  @override                 public void aftertextchanged(editable arg0) {                 }             });              return convertview;         }            @override         public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) {             string headertitle = (string) getgroup(groupposition);             if (convertview == null) {                 layoutinflater infalinflater = (layoutinflater) this.context.getsystemservice(context.layout_inflater_service);                 convertview = infalinflater.inflate(r.layout.e_list_group, null);             }              textview vw_header = (textview) convertview.findviewbyid(r.id.eheader);             vw_header.settypeface(null, typeface.bold);             vw_header.settext(headertitle);              return convertview;         }  // other overridden methods here....      } 

because of adapter functionality recycle views, whenever type text in edit box value either lost or copied in other edit boxes when scrolling , down.

in list view array used store values of edit boxes.

what best way in expandable list view? array of arrays? can provide example expandable list view , not list view?

edit: tried have problems:

public view getchildview(final int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) {         final string childtext = (string) getchild(groupposition, childposition);          if (convertview == null) {             layoutinflater infalinflater = (layoutinflater) this.context.getsystemservice(context.layout_inflater_service);             convertview = infalinflater.inflate(r.layout.e_list_item, null);         }          textview vw_text_sub = (textview) convertview.findviewbyid(r.id.esubt);         edittext vw_edit = (edittext) convertview.findviewbyid(r.id.eedit);          vw_text_sub.settext(childtext);         if(tmp[groupposition][childposition] != null) {             vw_edit.settext(tmp[groupposition][childposition]);         }else{             vw_edit.settext("");         }          vw_edit.addtextchangedlistener(new textwatcher() {              @override             public void ontextchanged(charsequence arg0, int arg1, int arg2, int arg3) {                 tmp[groupposition][childposition] = arg0.tostring();             }              @override             public void beforetextchanged(charsequence arg0, int arg1, int arg2, int arg3) {             }              @override             public void aftertextchanged(editable arg0) {             }         });          return convertview;     } 

tmp array string[10][10]. groups 3 , children max 7 in group, array not smaller data.

the problem testwatcher. fires each method lot of times , have not found out why. solution use focuschangelistener or better show alertdialog in order fill field. on positive button click stored data in array.

so replacing textwatcher managed solve problem.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -