I have tried it, but no do correct.

.java:
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.Button;

public class helloworld extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout layout = (LinearLayout) findViewById
(R.id.mainlayout);
        Button bt = new Button(this);
        bt.setText("Button");
        layout.addView(bt);
        setContentView(layout);
    }
}

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:id="@+id/mainlayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>



On 5月4日, 下午6时08分, 6real <xirgon...@gmail.com> wrote:
> Hi,
>
> did you try to :
>
> > give an ID to your layout
> > find it with the findViewById method
> > then you can add your view.
>
> Rgds,,
> C.
>
> On May 4, 11:28 am, "rjy...@gmail.com" <rjy...@gmail.com> wrote:
>
> > Hi
> >    I create a application and the main activity reference by the
> > main.xml.
> > The main.xml has a LinearLayout element. So my code is setContentView
> > (R.layout.main) to show the main window.I need add other element such
> > as Button or EditView, but I don't want add the XML line to the
> > main.xml.I hope use the layout.addView(...) to add the elements to my
> > Activity. So I need get the current LinearLayout object and can invoke
> > the addView function.
> > So How can I get the default layout?
> > Thanks.
> > --------------------
> > RongJun Ying
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to