c# - My AlertDialog is showed many time in adapter -


i problem when trying show alertdialog in adapter. it's showed many time when want delete article (the first article each category) or when try delete category (exactly when remove second category )

this code

articlesconfigurations.cs

using system; using system.collections.generic; using system.linq; using system.text; using android.app; using android.content; using android.os; using android.runtime; using android.util; using android.views; using android.widget; using symamobile.core.models; using vici.coolstorage; using symamobile.droid.adapters; using android.database;  namespace symamobile.droid { public class articlesconfiguration : fragment {     private listview listviewcatgarticles;     private listcategoriearticlesconfigadapter adaptercatconfig;     private listarticleconfigadapter adapterarticles;     private list<categoriesarticlesconfig> listcatgarticles;     private list<articlesconfig> listarticles;     private button ajouterarticle;     private gridview gridarticles;     private articlesconfig art;     private textview codebarre;     private textview libelle;     private categoriesarticlesconfig categorieactuelle;     private articles articleactuelle;     private cslist<categoriesarticles, int> catglist;     private spinner categorie;     private spinner articles;       public override view oncreateview (layoutinflater inflater, viewgroup container, bundle savedinstancestate)     {         view v = inflater.inflate(resource.layout.fragment_configuration_articles, container, false);          listviewcatgarticles = v.findviewbyid<listview>(resource.id.lv_articles_fragment_configuration_articles);         ajouterarticle = v.findviewbyid<button>(resource.id.bt_ajouter_fragment_configuration_articles);         gridarticles = v.findviewbyid<gridview>(resource.id.gv_articles_fragment_articles_configuration);          listcatgarticles = categoriesarticlesconfig.list().tolist<categoriesarticlesconfig>();         adaptercatconfig = new listcategoriearticlesconfigadapter(activity, listcatgarticles);         listviewcatgarticles.adapter = adaptercatconfig;          ajouterarticle.click += ajouterarticle_click;         listviewcatgarticles.itemclick += listviewcatgarticles_itemclick;          gridarticles.itemclick += gridarticles_itemclick;         return v;     }      void gridarticles_itemclick(object sender, adapterview.itemclickeventargs e)     {         if (e.position == gridarticles.count-1)         {             android.util.log.error("position grid", ""+e.position);             android.util.log.error("grid count", "" + gridarticles.count);              alertdialog.builder builder = new alertdialog.builder(activity);             builder.settitle(resource.string.ajouter_categorie);             layoutinflater inflater = activity.layoutinflater;             view v = inflater.inflate(resource.layout.alertdialog_ajouter_article_configuration, null);              codebarre = v.findviewbyid<textview>(resource.id.ed_code_barre_alert_dialog_ajouter_article_configuration);             libelle = v.findviewbyid<textview>(resource.id.tv_nom_article_alert_dialog_ajouter_article_configuration);             categorie = v.findviewbyid<spinner>(resource.id.sp_categories_alert_dialog_ajouter_article_configuration);             articles = v.findviewbyid<spinner>(resource.id.sp_articles_alert_dialog_ajouter_article_configuration);              var adapter = new arrayadapter<string>(activity, android.resource.layout.simplespinnerdropdownitem);              catglist = categoriesarticles.list();             (int = 0; < catglist.count; i++)             {                 adapter.add(catglist[i].nom);             }             categorie.itemselected += categorie_itemselected;             categorie.adapter = adapter;              codebarre.textchanged+=codebarre_textchanged;              builder.setpositivebutton(resource.string.ajouter, delegate             {                 if (articleactuelle != null && categorieactuelle != null)                 {                     articlesconfig = articlesconfig.new();                     a.article = articleactuelle;                     a.categoriearticles = categorieactuelle;                     a.save();                     listarticles.add(a);                     adapterarticles.notifydatasetchanged();                 }             });              builder.setnegativebutton(resource.string.annuler, (android.content.idialoginterfaceonclicklistener)null);             builder.setview(v);             builder.show();         }     }      void categorie_itemselected(object sender, adapterview.itemselectedeventargs e)     {         list<articles> = catglist[e.position].articles.tolist<articles>();          var adapter = new arrayadapter<string>(activity, android.resource.layout.simplespinnerdropdownitem);          (int = 0; < a.count; i++)         {             adapter.add(a[i].libelle);         }         articles.adapter = adapter;      }      private void codebarre_textchanged(object sender, android.text.textchangedeventargs e)     {         if (codebarre.text.length > 2)         {             articleactuelle = articles.readfirst("codebarre ='" + codebarre.text + "'");             if (articleactuelle != null)             {                 libelle.text = articleactuelle.libelle;             }             else             {                 libelle.text = "";             }         }     }      void listviewcatgarticles_itemclick(object sender, adapterview.itemclickeventargs e)     {         categorieactuelle = categoriesarticlesconfig.read((int)adaptercatconfig.getitemid(e.position));         listarticles = categorieactuelle.articlesconfig.tolist();         adapterarticles = new listarticleconfigadapter(activity, listarticles);         gridarticles.adapter = adapterarticles;     }      void ajouterarticle_click(object sender, eventargs e)     {         alertdialog.builder builder = new alertdialog.builder(activity);         builder.settitle(resource.string.ajouter_categorie);         layoutinflater inflater = activity.layoutinflater;         view v = inflater.inflate(resource.layout.alertdialog_ajouter_categorie_article_configuration, null);          textview nom = v.findviewbyid<textview>(resource.id.ed_nom_ajouter_categorie_fragment_article_configuration);          builder.setpositivebutton(resource.string.ajouter, delegate         {             if (nom.text.length > 0)             {                 categoriesarticlesconfig c = categoriesarticlesconfig.new();                 c.nom = nom.text;                 c.save();                  c = categoriesarticlesconfig.readfirst("categoriearticlesconfigid=" + c.categoriearticlesconfigid);                 listcatgarticles.add(c);                 adaptercatconfig.notifydatasetchanged();             }         });          builder.setnegativebutton(resource.string.annuler, (android.content.idialoginterfaceonclicklistener)null);         builder.setview(v);         builder.show();     } } } 

listcategoriearticlesconfigadapter.cs

namespace symamobile.droid.adapters { class listcategoriearticlesconfigadapter : baseadapter {      private list<categoriesarticlesconfig> list;     private int indice;     private activity activity;      public listcategoriearticlesconfigadapter(android.app.activity activity, list<categoriesarticlesconfig> list)         : base()     {         this.activity = activity;         this.list = list;     }      public override int count     {         { return list.count; }     }      public override java.lang.object getitem(int position)     {         return null;     }      public override long getitemid(int position)     {         return list[position].categoriearticlesconfigid;     }      public override android.views.view getview(int position, android.views.view convertview, android.views.viewgroup parent)     {         var view = (convertview ??           activity.layoutinflater.inflate(               resource.layout.list_item_categories_articles_configuration,               parent,               false)) linearlayout;          var nom = view.findviewbyid(resource.id.tv_nom_list_item_categories_articles_configuration) textview;         var modify = view.findviewbyid(resource.id.bt_modify_list_categories_articles_configuration) button;         var delete = view.findviewbyid(resource.id.bt_delete_list_categories_articles_configuration) button;          modify.click += modify_click;         indice = position;          delete.click +=delete_click;          nom.text = list[position].nom;          return view;     }      void delete_click(object sender, eventargs e)     {         android.app.alertdialog.builder builder = new android.app.alertdialog.builder(activity);         builder.setmessage(resource.string.msg_supprimer);         builder.setpositivebutton(resource.string.oui, delegate         {             csdatabase.executenonquery("delete categoriesarticlesconfig categoriearticlesconfigid=" + list[indice].categoriearticlesconfigid);             list.removeat(indice);             notifydatasetchanged();         });         builder.setnegativebutton(resource.string.non, (android.content.idialoginterfaceonclicklistener)null);         builder.show();     }      void modify_click(object sender, eventargs e)     {         alertdialog.builder builder = new alertdialog.builder(activity);         builder.settitle(resource.string.modifier_categorie);         layoutinflater inflater = activity.layoutinflater;         view v = inflater.inflate(resource.layout.alertdialog_ajouter_categorie_article_configuration, null);          textview _nom = v.findviewbyid<textview>(resource.id.ed_nom_ajouter_categorie_fragment_article_configuration);          _nom.text = list[indice].nom;            builder.setnegativebutton(resource.string.annuler, (android.content.idialoginterfaceonclicklistener)null);         builder.setpositivebutton(resource.string.modifier, delegate {             categoriesarticlesconfig c = categoriesarticlesconfig.readfirst("categoriearticlesconfigid=" + list[indice].categoriearticlesconfigid);             if (c != null)             {                 c.nom = _nom.text;                 c.save();             }             list[indice].nom = _nom.text;             notifydatasetchanged();         });         builder.setview(v);         builder.show();     } } } 

listarticleconfigadapter

namespace symamobile.droid.adapters { class listarticleconfigadapter : baseadapter {     activity context;     private list<articlesconfig> liste;     private int indice;      public listarticleconfigadapter(activity context, list<articlesconfig> liste)         : base()     {         this.context = context;         this.liste = liste;     }      public override int count     {         { return liste.count+1; }     }      public override long getitemid(int position)     {         return position;     }      public override android.views.view getview(int position, view convertview, viewgroup parent)     {         var view = (convertview ??           context.layoutinflater.inflate(               resource.layout.list_item_article_configuration,               parent,               false)) linearlayout;          var image = view.findviewbyid(resource.id.iv_list_item_article_configuration) imageview;         var nom = view.findviewbyid(resource.id.tv_nom_article_list_item_article_configuration) textview;         var supprimer = view.findviewbyid(resource.id.bt_delete_list_item_article_configuration) button;          android.util.log.error("position : ", ""+position+" list count : "+liste.count);          if (position < liste.count)         {             nom.text = liste[position].article.libelle;             image.setimagebitmap(tools.imagetools.stringtobitmap(liste[position].article.image));         }         else         {             nom.text = context.resources.getstring(resource.string.ajouter);             image.setimageresource(resource.drawable.add128x128);             supprimer.visibility = viewstates.invisible;         }         indice = position;          supprimer.click += supprimer_click;          return view;     }      void supprimer_click(object sender, eventargs e)     {         android.app.alertdialog.builder builder = new android.app.alertdialog.builder(context);         builder.setmessage(resource.string.msg_supprimer);         builder.setpositivebutton(resource.string.oui, delegate         {             csdatabase.executenonquery("delete articlesconfig articlesconfigid=" + liste[indice].articlesconfigid);             liste.removeat(indice);             notifydatasetchanged();         });         builder.setnegativebutton(resource.string.non, (android.content.idialoginterfaceonclicklistener)null);         builder.show();      }      public override java.lang.object getitem(int position)     {         return position;     } } } 

thank in advance

u have need code on next activity onbackpress or

@override protected void onpause() {     // todo auto-generated method stub     super.onpause();     progressdialog.dismiss(); }    @override public void onbackpressed() {     // todo auto-generated method stub     super.onbackpressed();      system.exit(0); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -