Reputation: 10267
My code compiles fine, and when I start the Activity, its associated layout is displayed, but the widgets I dynamically create thereafter in the onCreate() do not display.
Why wouldn't they?
Eclipse doesn't drop into the Debug Perspective, they simply don't show up.
Here's the relevant code:
public class Authorize_Activity_DynamicControls extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ondemandandautomatic_dynamicauthorize);
LinearLayout llay = new LinearLayout(this);
llay.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
llp.weight = 1.0f;
CheckBox cb = new CheckBox(getApplicationContext());
cb.setText("1");
cb.setLayoutParams(llp);
llay.addView(cb);
ScrollView svh = (ScrollView) findViewById(R.id.scrollViewHost);
svh.addView(llay);
}
...and here's the layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/demand"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/time"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/space"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/contact"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ScrollView
android:id="@+id/scrollViewHost"
android:fillViewport="true"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</ScrollView>
</LinearLayout>
Upvotes: 0
Views: 153
Reputation: 594
You shouldn't need to invalidate the views you've added in onCreate(). Without having the XML layout file it's also some guesswork to try to answer the post confidently. Have you tried using a TextView instead of checkbox?
Upvotes: 1
Reputation: 4960
you might need to invalidate the whole view manually to get the desired result, so try adding this line to the end:
svh.invalidate();
Upvotes: 1