java - How to display AlertDialog on List Adapter -


contactsdatalist array list contains data of contacts.

i have written following code pass data list adapter

adapter= new contactsadapter(getapplicationcontext(), contactsdatalist); listview = (listview) findviewbyid(r.id.lv_contacts); listview.setadapter(adapter); 

on list view, want launch call_action event, whenever user clicks on item in list.

i have written following code in adapter, giving me error message

java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity.

contactsheading.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(final view v) {          alertdialog alertdialog = new alertdialog.builder(context).create();         alertdialog.settitle("alert");         alertdialog.setmessage("are sure want call "+contactsheading + "?"  );         alertdialog.setbutton(alertdialog.button_positive, "ok",                 new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog, int which) {                         intent intent = new intent(intent.action_call, uri.parse("tel:" + contactstext));                         if (activitycompat.checkselfpermission(v.getcontext(), manifest.permission.call_phone) != packagemanager.permission_granted) {                              return;                         }                         v.getcontext().startactivity(intent);                     }                 });         alertdialog.setbutton(alertdialog.button_negative, "cancel",                 new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog, int which) {                          dialog.dismiss();                     }                 });         alertdialog.show(); 

kindly guide me how resolve error message.

this caused context passed alertdialog.builder.

in line:

alertdialog alertdialog = new alertdialog.builder(context).create(); 

replace

context 

with

[youractivityname].this 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -