oncheckedchangelistener for checkbox in android -
in applications have checkbox dynamically added. in application when click on 1 of check box n click on ok buton i'm performing operations.below code.its not working on click of check box. please tell me should do?
public class importfile extends activity{ tablelayout tl; intent i; imageview im; int idcount; textview nameoffile,sizeoffile,line; checkbox[] ch=new checkbox[100]; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.mylist); tl=(tablelayout) findviewbyid(r.id.table); file file = new file(environment.getexternalstoragedirectory() + file.separator + "gallery" //folder name ); if (!file.exists()) { file.mkdirs(); } /* i=new intent(); i.putextra("file","string"); setresult(result_ok, i); finish(); */ tablerow tr=new tablerow(this); int id=1; file f = new file("/sdcard/download");//or environment.getexternalstoragedirectory().getpath() file[] files = f.listfiles(); for(int = 0; < files.length; i++) { file file1 = files[i]; //take file name long size = file1.length()/1024; string myfile = file1.getpath().substring(file1.getpath().lastindexof("/")+1,file1.getpath().length()).tolowercase(); if(myfile.endswith(".jpeg")||myfile.endswith(".png")|| myfile.endswith(".gif") || myfile.endswith(".jpg")) { ch[id]=new checkbox(this); ch[id].setid(id); ch[id].settext(" "); system.out.println("id is........"+id); bitmap b=thumbnailutils.extractthumbnail(bitmapfactory.decodefile((file1.getpath())), 40,40); im=new imageview(this); im.setimagebitmap(b); nameoffile=new textview(this); nameoffile.settext(" "+myfile); nameoffile.setwidth(200); sizeoffile=new textview(this); sizeoffile.settext(size+"kb"); sizeoffile.setwidth(100); tr=new tablerow(this); tr.setlayoutparams(new layoutparams(layoutparams.wrap_content,layoutparams.wrap_content)); if((id%2)==0) { tr.setbackgroundresource(r.color.thistle); } else{ tr.setbackgroundresource(r.color.bisque); } tr.addview(ch[id++]); idcount=id; tr.addview(im); tr.addview(nameoffile); tr.addview(sizeoffile); tl.addview(tr,new tablelayout.layoutparams(layoutparams.fill_parent,layoutparams.wrap_content)); } } } int j; public void ok(view v) { (j=1;j<idcount;j++) { ch[j].setoncheckedchangelistener(new oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { system.out.println("checked id :: " + ch[j].getid()); } }); } } }
try this
onclicklistener checkboxlistener; checkboxlistener =new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub if(checkbox1.ischecked()) { toast.maketext(getbasecontext(), "something", toast.length_short).show(); } } }; checkbox1.setonclicklistener(checkboxlistener);
android checkbox oncheckedchanged
No comments:
Post a Comment