java - Andriod add header and footer programmicatlly -
i have following code need add programmatically "simple" fixed header ( image) , footer (with button) using relative layout:
/* sample application create items, need header image , footer button*/ import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.app.activity; import android.graphics.typeface; import android.os.bundle; import android.view.view; import android.view.viewgroup.layoutparams; import android.view.window; import android.widget.button; import android.widget.checkbox; import android.widget.imageview; import android.widget.compoundbutton; import android.widget.compoundbutton.oncheckedchangelistener; import android.widget.linearlayout; import android.widget.scrollview; import android.widget.toast; public class mainactivity extends activity { scrollview scrollview; button dynamicbtn; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // requestwindowfeature(window.feature_no_title); //appcompactivity on public class setcontentview(r.layout.activity_main); scrollview = new scrollview(this); linearlayout linearlayout = new linearlayout(this); linearlayout.setorientation(linearlayout.vertical); scrollview.addview(linearlayout); imageview imagetop = new imageview(this); imagetop.setbackgroundresource(r.mipmap.ic_launcher ); imagetop.setmaxheight(50); imagetop.setmaxwidth(50); linearlayout.addview(imagetop); for(int = 0; i<25;i++) { linearlayout linear1 = new linearlayout(this); linear1.setorientation(linearlayout.horizontal); linearlayout.addview(linear1); imageview image = new imageview(this); image.setbackgroundresource(r.mipmap.ic_launcher ); image.setmaxheight(50); image.setmaxwidth(50); linear1.addview(image); dynamicbtn = new button(this); dynamicbtn.settext("button no... "+i); dynamicbtn.setid(i); dynamicbtn.settextsize(10); dynamicbtn.setpadding(8, 3, 8, 3); dynamicbtn.settypeface(typeface.serif,typeface.bold_italic); dynamicbtn.setlayoutparams(new layoutparams(layoutparams.wrap_content,layoutparams.wrap_content)); linear1.addview(dynamicbtn); dynamicbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { toast.maketext(getapplicationcontext(), "yipee.."+ v.getid(), toast.length_short).show(); } }); checkbox dynamicchk = new checkbox(this); dynamicchk.setid(i); dynamicchk.settext("wow..a checkbox" + i); linear1.addview(dynamicchk); dynamicchk.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton arg0, boolean arg1) { toast.maketext(getapplicationcontext(), "checked.."+ arg0.getid() + " " + arg1, toast.length_short).show(); } }); } this.setcontentview(scrollview); } }
Comments
Post a Comment