Sunday, 15 January 2012

Add layout in method android -



Add layout in method android -

i know how can create method add together linearlayout other layout. want create method when utilize method in activity, method add together linear layout in top of activity layout. how can that?

edit: that:

public class secondactivity extends activity { linearlayout layout; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.second_activity); layout = (linearlayout) findviewbyid(r.id.lay); button next = (button) findviewbyid(r.id.nextactivity); layout.addview(addnewlinearlayout(getapplicationcontext())); next.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(secondactivity.this, thirdactivity.class); startactivity(intent); } }); } private view addnewlinearlayout(context context) { linearlayout linearlayout = new linearlayout(context); linearlayout.layoutparams params = new linearlayout.layoutparams(layoutparams.match_parent, layoutparams.wrap_content); linearlayout.setlayoutparams(params); linearlayout.setbackgroundcolor(getresources().getcolor(r.color.black)); // else here on linear layout or customize linear layout homecoming linearlayout; } }

and xml:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lay" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <button android:id="@+id/nextactivity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button" android:layout_margintop="100dp" /> </linearlayout>

but layout not changing color. why?

try :

private view _addnewlinearlayout(context) { linearlayout linearlayout = new linearlayout(context); linearlayout.layoutparams params = new linearlayout.layoutparams(layoutparams.match_parent, layoutparams.wrap_content); linearlayout.setlayoutparams(params); // else here on linear layout or customize linear layout homecoming linearlayout; }

in main phone call :

getview().addview(_addnewlinearlayout(context));

android android-layout

No comments:

Post a Comment