java - Dynamically Add onClick ActionListener to CheckBox in Android -


i creating application, creates checkboxes dynamically number of entries in database.

the code runs fine. , creates number of checkboxes. want add onclick action listener checkboxes, dynamically. how this.

i posting code here:

sqlitedatabase db = this.getreadabledatabase();  string countquery = "select  * " + table_name; sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(countquery, null);  int maxcount = cursor.getcount(); checkbox[] check = new checkbox[maxcount];  cursor.movetofirst(); int checkboxid = 100; int alarm_id; for(int i=0;i<maxcount;i++) {     check[i]= new checkbox(this); setcheckboxid(i+maxcount); } 

now how add actionlistener these dynamically created checkboxes.

check[i]= new checkbox(this); check[i].setonclicklistener(this); 

you want check against checkbox id or set tag text boz when creating it.

check[i].settag(someidentifier); 

then use method

@override public void onclick(view v) {                  if (v.gettag.equals(someidentifier)){                     //do stuff here                   }          } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -