android - How to update TextView of custom ArrayAdapter on the basis of EditText? -


i have custom arrayadapter horizontal linearlayout containing 02 edittext fields , 01 textview.....all set take/show numberdecimals.

all want whenever number input in of edittext fields, product of 2 numbers (edittext 1 & edittext 2) shown in textview.

i've tried both onfocuschangedlistener , textchangedlistener textview doesnt updated during live entries. doesnt show anything.

i'm new programming, cant find other solution that. in advance!

below adapter code:

textview labelview; edittext ratioview; edittext rateview; textview avgview;   public fibresadapter(activity context, arraylist<fibres> fibreslist) {     super(context, 0, fibreslist); }  @nonnull @override public view getview(int position, @nullable view convertview, @nonnull viewgroup parent) {     if (convertview == null) {         convertview = layoutinflater.from(getcontext()).inflate(r.layout.list_item, parent, false);     }     final fibres currentfibre = getitem(position);      labelview = (textview) convertview.findviewbyid(r.id.label);     labelview.settext(currentfibre.fibrelabel);      ratioview = (edittext) convertview.findviewbyid(ratio);     rateview = (edittext) convertview.findviewbyid(r.id.rate);     avgview = (textview) convertview.findviewbyid(r.id.avg);      ratioview.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) {             if (s.tostring().length() > 0) {                 currentfibre.fibreratio = double.parsedouble(s.tostring());                 avgview.settext("testing");             } else {                 currentfibre.fibreratio = 0;             }         }          @override         public void aftertextchanged(editable s) {          }     });      rateview.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) {             if (s.tostring().length() > 0) {                 currentfibre.fibrerate = double.parsedouble(s.tostring());                 avgview.settext("testing");             } else {                 currentfibre.fibrerate = 0;             }         }          @override         public void aftertextchanged(editable s) {          }     });      return convertview; } 

below code activity:

double totalavg; double totalratio;  textview totalavgview; textview totalratioview;  static arraylist<fibres> fibres;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.fibres_list);      fibres = new arraylist<>();     int x = 0;      while (x < fibres.fibcatarray.length) {         fibres.add(new fibres(fibres.fibcatarray[x]));         x++;     }      listview listview = (listview) findviewbyid(r.id.list);     fibresadapter adapter = new fibresadapter(this, fibres);      listview.setadapter(adapter);      totalratioview = (textview) findviewbyid(r.id.total_ratio);     totalavgview = (textview) findviewbyid(r.id.total_avg);  }  public void displaytotals() {     totalratio = 0;     totalavg = 0;      (fibres materials : fibres) {         totalratio += materials.fibreratio;         totalavg += (materials.fibreratio / 100 * materials.fibrerate);     }     totalratioview.settext(totalratio + "");     totalavgview.settext(totalavg + "");  }  public boolean validatedata() {     if (totalratio != 100) {         toast.maketext(this, "total should 100%!", toast.length_short).show();         return false;     }      (fibres materials : fibres) {         if (materials.fibreratio > 1 && materials.fibrerate <= 0) {             toast.maketext(this, "enter both ratio & rate!", toast.length_short).show();             return false;         }     }     return true; } 

in adapter add addtextchangedlistener both edittext , use textview.settext() inside that. this.

edittext1.addtextchangedlistener(new textwatcher() {     @override    public void aftertextchanged(editable s) {}     @override        public void beforetextchanged(charsequence s, int start,      int count, int after) {    }     @override        public void ontextchanged(charsequence s, int start,      int before, int count) {       if(s.length() != 0)         textview.settext("");    }   }); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -