android - how Create setAdapter() for a AlertDialog -


i created customdialogbuilder extends dialog... want create method setapater().. created section onclick method on adapter not working..

my customdialogbuilder class given below.

public class customalertdialog extends dialog  {     public customalertdialog(context c, int theme) {         super(c, theme);     }     public static class builder      {         private context context;         private string title;         private string message;         private string positivebuttontext;         private string negativebuttontext;         private view contentview;         private listadapter adapter;         private  listview listview;         private dialoginterface.onclicklistener                          positivebuttonclicklistener,                         negativebuttonclicklistener,adapterlistener;         public builder(context c)         {             context =c;         }         public builder settitle(string title)         {             this.title =title;             return this;         }         public builder setmessage(string message) {             this.message = message;             return this;         }         public builder setcontentview(view v)         {             contentview =v;             return this;         }         public builder setadapter(listadapter adapter,dialoginterface.onclicklistener listener)         {             this.adapter=adapter;             return this;         }         public builder setpositivebutton(string positivebuttontext,                 dialoginterface.onclicklistener listener) {             this.positivebuttontext = positivebuttontext;             this.positivebuttonclicklistener = listener;             return this;         }         public builder setnegativebutton(string negativebuttontext,                 dialoginterface.onclicklistener listener) {             this.negativebuttontext = negativebuttontext;             this.negativebuttonclicklistener = listener;             return this;         }         public customalertdialog create()         {             layoutinflater inflater = (layoutinflater) context                     .getsystemservice(context.layout_inflater_service);             final customalertdialog dialog = new customalertdialog(context,                      r.style.dialog);             view layout = inflater.inflate(r.layout.dialog_title_layout, null);             dialog.addcontentview(layout, new layoutparams(layoutparams.fill_parent,layoutparams.wrap_content));             ((textview) layout.findviewbyid(r.id.tv_custom_dialog_title)).settext(title);             if (positivebuttontext != null) {                 ((button) layout.findviewbyid(r.id.bt_custom_dialog_positive))                         .settext(positivebuttontext);                 if (positivebuttonclicklistener != null) {                     ((button) layout.findviewbyid(r.id.bt_custom_dialog_positive))                             .setonclicklistener(new view.onclicklistener() {                                 public void onclick(view v) {                                     positivebuttonclicklistener.onclick(                                             dialog,                                              dialoginterface.button_positive);                                 }                             });                 }             }             else                 layout.findviewbyid(r.id.bt_custom_dialog_positive).setvisibility(                         view.gone);              if (negativebuttontext != null) {                  ((button) layout.findviewbyid(r.id.bt_custom_dialog_negative))                          .settext(negativebuttontext);                  if (negativebuttonclicklistener != null) {                      ((button) layout.findviewbyid(r.id.bt_custom_dialog_negative))                              .setonclicklistener(new view.onclicklistener() {                                  public void onclick(view v) {                                      positivebuttonclicklistener.onclick(                                             dialog,                                               dialoginterface.button_negative);                                  }                              });                  }              } else {                  // if no confirm button set visibility gone                  layout.findviewbyid(r.id.bt_custom_dialog_negative).setvisibility(                          view.gone);              }              if (message != null) {                  ((textview) layout.findviewbyid(                         r.id.tv_custom_dilaog_message)).settext(message);              }              else if(adapter!=null)              {                  listview = new listview(context);                  listview.setadapter(adapter);                  ((linearlayout) layout.findviewbyid(r.id.layout_custom_dialog_content))                  .removeallviews();          ((linearlayout) layout.findviewbyid(r.id.layout_custom_dialog_content))          .addview(listview);          if(adapterlistener!=null)          {              listview.setonitemclicklistener(new onitemclicklistener() {                  public void onitemclick(adapterview<?> arg0, view arg1,                         int arg2, long arg3) {                   }             });          }               }              else if (contentview != null) {                  // if no message set                  // add contentview dialog body                  ((linearlayout) layout.findviewbyid(r.id.layout_custom_dialog_content))                          .removeallviews();                  ((linearlayout) layout.findviewbyid(r.id.layout_custom_dialog_content))                          .addview(contentview,                                   new layoutparams(                                          layoutparams.wrap_content,                                           layoutparams.wrap_content));              }             return dialog;         }     } } 

how can create correct setadapter() similar setadapter() in alertdialog.

this how create dialog using class:

dialog dialog = null;                     string[] items = {"edit profile","change doctor","change password","logout"};                     arrayadapter<string> adapter = new arrayadapter<string>(loged.this,                             r.layout.my_spinner_layout, items);                  customalertdialog.builder custombuilder = new                         customalertdialog.builder(loged.this);                     custombuilder.settitle("options")                        .setadapter(adapter, new dialoginterface.onclicklistener() {                          public void onclick(dialoginterface dialog, int which) {                             log.e("dis",""+which);                          }                     });                     dialog = custombuilder.create();                     dialog.show(); 

hureyyy...... got answer........

change setadapter function in our customdialog class...

public builder setadapter(listadapter adapter,dialoginterface.onclicklistener listener)         {             this.adapter=adapter;             this.adapterlistener=listener;             return this;         } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -