I am trying to create an activity UI by setting buttons and text dynamically. Just to get started I have dynamically created a ScrollView that contains a LinearLayout which contains a TextView and two Buttons. Everything is created dynamically. There is no layout file for this activity. I can get the two buttons to appear on the android emulator, but the text will not appear. I can see the Scrollview in the debugger and it has three elements in side it, a TextView and two Buttons. Everything looks okay in the debugger. Can somebody give me an idea on how to get the text to appear?
Here is the code that creates the dynamic TextView: public static TextView CreateTextView(Context context, int id, float size, int color, int gravity, int width, int height, String text) { TextView t = new TextView(context); t.setId(id); t.setTextSize(TypedValue.COMPLEX_UNIT_SP,size); t.setTextColor(color); t.setGravity(gravity); t.setLayoutParams(new LinearLayout.LayoutParams(width, height)); t.setText(text); return t; } Here is the onCreate code that appears inside of onCreate for the activity. This onCreate code is called to create the ScrollView, LinearLayout, the TextView and the two Buttons dynamically. Like I said above, the buttons appear, but the text does not. super.onCreate(savedInstanceState); final Resources res = getResources(); ScrollView s = DynamicLayout.CreateScrollView(this, 1, true, LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); LinearLayout q = DynamicLayout.CreateLinearLayout(this, 1, LinearLayout.VERTICAL, 0x11 /* CENTER=0x11, LEFT=3, RIGHT=5 */, LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); s.addView(q); TextView t = DynamicLayout.CreateTextView(this, 2, 30.0f, 0xffffff, 0x11 /* CENTER=0x11, LEFT=3, RIGHT=5 */, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, res.getString(R.string.EstablishmentName)); q.addView(t); Button b = DynamicLayout.CreateButton(this, 3, 0x11 /* CENTER=0x11, LEFT=3, RIGHT=5 */, 291, 43, res.getDrawable(R.drawable.spot_ticket_red)); q.addView(b); b = DynamicLayout.CreateButton(this, 4, 0x11 /* CENTER=0x11, LEFT=3, RIGHT=5 */, 291, 43, res.getDrawable(R.drawable.spot_ticket_green)); q.addView(b); setContentView(s); -- 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