Ok this is what I want to do. Assume I have a XML file that described
my screen.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/page1layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<AnalogClock android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
</AnalogClock>
</RelativeLayout>
Now what I want to do is programmatically add this to a view. I am
doing this at the moment but it is giving me a NullPointer exception
RelativeLayout layout2 = (RelativeLayout)
findViewById(R.id.page1layout);
RelativeLayout.LayoutParams linear2layout = new
RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
linear2layout.addRule(RelativeLayout.ALIGN_WITH_PARENT_TOP);
page2.addView(layout2, linear2layout);
where page2 is of type RelativeLayout.
Any idea what is going wrong here? If I dynamically create a TextView
like below then it works...
TextView text2 = new TextView(this);
text2.setText("can be any bunch of widgets here...blah blah");
RelativeLayout.LayoutParams linear2layout = new
RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
linear2layout.addRule(RelativeLayout.ALIGN_WITH_PARENT_TOP);
page2.addView(text2, linear2layout);
So all I was trying to do is replace the TextView with the UI
described in the XML file.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---