package app.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Test extends Activity {
TextView myTextView;
private static boolean inflate = true;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (inflate)
inflateXMLLayout();
else
constructLayout();
}
private void inflateXMLLayout() {
setContentView(R.layout.main);
myTextView = (TextView) findViewById(R.id.myTextView);
}
private void constructLayout() {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
LinearLayout.LayoutParams textViewLP = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
myTextView = new TextView(this);
myTextView.setText("Hello World, HelloWorld");
ll.addView(myTextView, textViewLP);
addContentView(ll, lp);
}
}
//main.xml
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/myTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, HelloWorld"
/>