android - How to bind Radio Buttons using RxJava -
i'm following code of qiitanium app (see highlighted lines in link) , have trouble figuring out how can bind radiobuttons
say have radiogroup r.id.rgmybuttons id , contains 3 radiobuttons "dead", "alive", "body missing" ids r.id.rbdead, r.id.rbalive, r.id.rbmissing
i set radiogroup field as
rx<radiogroup> radiogroup;
i view set in onviewcreated as
rdgroup = rxview.findbyid(this, r.id.rgmybuttons); rdgroup.get().setoncheckedchangelistener(monpersonstateupdatelistener);
in onbind, i'd bind radiogroup model data value returns maps directly correct radiobutton in group. i'm looking like
rdgroup.bind(person.state(), rxactions.someaction()),
so bound radiogroup , automatically sets correct value.
the person_state() returns 2 dead, 3 alive , 4 missing , want check correct field in radiogroup. how can achieve in rxandroid?
i able solve on own. here's answer might come across same issue....
i wrote function in class as
protected rxaction<radiogroup, string> setradiobutton() { return new rxaction<radiogroup, string>() { @override public void call(final radiogroup radiogroup, final string selection) { radiobutton rb; switch(selection) { case "2": rb = (radiobutton)findviewbyid(r.id.rbdead); rb.setchecked(true); break; case "3": rb = (radiobutton)findviewbyid(r.id.rbalive); rb.setchecked(true); break; case "4": rb = (radiobutton)findviewbyid(r.id.rbmissing); rb.setchecked(true); break; } } }; }
and inside onbind used
rdgroup.bind(person.state(), setradiobutton()),
Comments
Post a Comment