android - More than one contentDescription for a button -
in activity
have method reads contentdescriptio
n of button , phone number , calls it.
i have list of departments in company. if same department have more 1 number should do. how add more 1 contentdescription
button pop dialog allows user choose between number should call.
public class contactus extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_contact_us); imageview = (imageview) findviewbyid(r.id.back); back.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(contactus.this , introduction.class); startactivity(i); overridependingtransition(r.animator.slide_in, r.animator.slide_out); } }); } public void onclickcall(view view) { final string phonenumber = view.getcontentdescription().tostring().trim(); dialoginterface.onclicklistener dialogclicklistener = new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { switch (which){ case dialoginterface.button_positive: //yes button clicked intent intent = new intent(intent.action_dial, uri.parse("tel://" + phonenumber)); startactivity(intent); break; case dialoginterface.button_negative: //no button clicked break; } } }; alertdialog.builder builder = new alertdialog.builder(this); builder.setmessage("test alert").setpositivebutton("yes", dialogclicklistener) .setnegativebutton("no", dialogclicklistener).show(); } public void onclickmail(view view) { string mailaddress = view.getcontentdescription().tostring().trim(); intent intent = new intent(intent.action_send); intent.settype("plain/text"); intent.putextra(intent.extra_email, new string[] { mailaddress}); intent.putextra(intent.extra_subject, "subject"); intent.putextra(intent.extra_text, "mail body"); startactivity(intent.createchooser(intent, "")); } }
when setting content description button append them commas separated.
after appending phone numbers content description //phonenumber1,phonenumber2,phonenumber3
now read content description view
final string allphonenumbers = view.getcontentdescription().tostring().trim(); //say phonenumber1,phonenumber2,phonenumber3 string[] arrphonenumbers = allphonenumbers .split(",");
now have phone numbers in array.
Comments
Post a Comment