android - Linking two EditText boxes for unit conversion -
i'm trying come scalable way link 2 edit text boxes unit conversion. user enter value in either of boxes , converted value show in other.
i make when 1 edittext edited, input, pass through method convert value , set text of other field.
the problem have lot of these pairs , each pair used convert different kind unit. if used textwatcher each box, can see start out of hand.
i thought extending textwatcher pass edittext view , partner's view, i'm not sure how pass kind of conversion method needs used. assign int each kind of conversion , use switch, doesn't seem solution me.
is there better way?
this how it. create class, partneredittextinfo ,which contains reference number , edittext obj. attach tag every edittext in app. set edittext in partneredittextinfo partner edittext , have unique reference number. every edittext can hold of partner.
extend edittext class , on ride ontextchanged() method call common conversion method(this can static class static method) . can partner edittext getting tag object of edittext text has changed. ,based on pairs of edittext(based on reference number) changed apply required conversion formula , settext on both edittexts in pair.
caution- need have way make sure wont infinite loop, have sort of flag differentiate changes edittext's text made user , made conversion method.
Comments
Post a Comment