i have 2 buttons, both of them barcode scanning. once returns scanning, want know button user clicked can take different path on "onactivityresult" method. how do that?
i can find out button clicked inside onclick() method won't help.
public class readeractivity extends appcompatactivity { private button scan_btn, verifybutton; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_reader); scan_btn = (button) findviewbyid(r.id.scan_btn); verifybutton = (button) findviewbyid(r.id.buttonverify); final activity activity = this; scan_btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { intentintegrator integrator = new intentintegrator(activity); integrator.setdesiredbarcodeformats(intentintegrator.all_code_types); integrator.setprompt("scan"); integrator.setcameraid(0); integrator.setbeepenabled(false); integrator.setbarcodeimageenabled(false); integrator.initiatescan(); } }); verifybutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { intentintegrator integrator = new intentintegrator(activity); integrator.setdesiredbarcodeformats(intentintegrator.all_code_types); integrator.setprompt("line barcode scanner"); integrator.setcameraid(0); integrator.setbeepenabled(false); integrator.setbarcodeimageenabled(false); integrator.initiatescan(); } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { intentresult result = intentintegrator.parseactivityresult(requestcode, resultcode, data); if(result != null){ if(result.getcontents()==null){ toast.maketext(this, "you cancelled scanning", toast.length_long).show(); } else { toast.maketext(this, result.getcontents(),toast.length_long).show(); } } else { super.onactivityresult(requestcode, resultcode, data); } } }
you can add boolean value inside activity
eg :
private boolean isscanbuttonclicked;
use below code
scan_btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { isscanbuttonclicked = true; // true scan button clicked intentintegrator integrator = new intentintegrator(activity); integrator.setdesiredbarcodeformats(intentintegrator.all_code_types); integrator.setprompt("scan"); integrator.setcameraid(0); integrator.setbeepenabled(false); integrator.setbarcodeimageenabled(false); integrator.initiatescan(); } }); verifybutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { isscanbuttonclicked = false; // false scan button not clicked intentintegrator integrator = new intentintegrator(activity); integrator.setdesiredbarcodeformats(intentintegrator.all_code_types); integrator.setprompt("line barcode scanner"); integrator.setcameraid(0); integrator.setbeepenabled(false); integrator.setbarcodeimageenabled(false); integrator.initiatescan(); }
according isscanbuttonclicked value can perform action inside onactivityresult()
hope these you.
Comments
Post a Comment