Android set intent class file by variable -
i trying utilize layoutinflater inflate buttons array lists. have 3 array lists: 1 button text, 1 button image, , 1 class file in go when clicked. have text , images working when inflating buttons can not switch class file when clicked. have tried looking solution have not found fit needs. help appreciated.
here code:
viewgroup parent; layoutinflater inflater; textview btext; imageview bimage; parent = (viewgroup) findviewbyid(r.id.container); inflater = (layoutinflater) getapplicationcontext().getsystemservice(context.layout_inflater_service); string[] text = {"news","chat"}; string[] image = {"news","chat"}; string[] link = {"main","chat"}; int size = text.length; for(int = 0; < size; i++) { view view = inflater.inflate(r.drawable.button, null); int imageid = getresources().getidentifier(image[i], "drawable", getpackagename()); bimage = (imageview) view.findviewbyid(r.id.ihome); bimage.setimageresource(imageid); btext = (textview) view.findviewbyid(r.id.thome); btext.settext(text[i]); parent.addview(view); final string theclass = link[i]; btext.setonclicklistener(new onclicklistener() { public void onclick(view v) { // todo auto-generated method stub intent blink = new intent(); blink.setclassname(getapplicationcontext(), theclass); startactivity(blink); } }); }
edit: clarify when click of buttons crashes saying cannot find , asking if has been declared in androidmanifest.xml is.
first parameter of blink.setclassname() bundle context. seek calling this.
blink.setclassname(packagename, fullyqualifiedactivityname); getapplicationcontext().startactivity(blink);
android variables android-intent
No comments:
Post a Comment