[android-beginners] Re: how to create a widget dynamically after setContenView

2008-05-08 Thread Megha Joshi
You can always create layouts programatically, and it is also possible to
add widgets programatically to the layouts declared in xml files.
All widgets provide constructors which you can use to create them
programatically..There are methods corresponding to each xml attribute for
any widget, so you can set properties programatically. Check out the
documentation on widgets for those.

For example, you can add a TextView to your xml declared layout as follows:

LinearLayout l = (LinearLayout)findViewById(R.id.widget27);
TextView label = new TextView(this);
label.setText(test);
l.addView(label, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));

Hope that helps.

-Megha

On Wed, May 7, 2008 at 5:47 PM, rukiman [EMAIL PROTECTED] wrote:


 Ok I want to be able to create a widget dynamically after a
 setContentView. Here is what I have so far:


 public class Demo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
 }


 ?xml version=1.0 encoding=utf-8?
 LinearLayout
 android:id=@+id/widget27
 android:layout_width=fill_parent
 android:layout_height=fill_parent
 xmlns:android=http://schemas.android.com/apk/res/android;
 android:orientation=vertical
 
 Button
 android:id=@+id/widget28
 android:layout_width=wrap_content
 android:layout_height=wrap_content
 android:text=Hit me!
 
 /Button
 /LinearLayout


 Now after the line:
 setContentView(R.layout.main);

 can I add another button to the LinearLayout? How do I do this? This
 is an oversimplification of what I want to do, hence the question
 might sound silly.

 If this is not possible, how can I create the above UI represented by
 the XML file programmatically?
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
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-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: how to create a widget dynamically after setContenView

2008-05-08 Thread dolan kundu
Hello,
yes , you can add .

On Thu, May 8, 2008 at 6:17 AM, rukiman [EMAIL PROTECTED] wrote:


 Ok I want to be able to create a widget dynamically after a
 setContentView. Here is what I have so far:


 public class Demo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
 }


 ?xml version=1.0 encoding=utf-8?
 LinearLayout
 android:id=@+id/widget27
 android:layout_width=fill_parent
 android:layout_height=fill_parent
 xmlns:android=http://schemas.android.com/apk/res/android;
 android:orientation=vertical
 
 Button
 android:id=@+id/widget28
 android:layout_width=wrap_content
 android:layout_height=wrap_content
 android:text=Hit me!
 
 /Button
 /LinearLayout


 Now after the line:
 setContentView(R.layout.main);

 can I add another button to the LinearLayout? How do I do this? This
 is an oversimplification of what I want to do, hence the question
 might sound silly.

 If this is not possible, how can I create the above UI represented by
 the XML file programmatically?
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
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-beginners?hl=en
-~--~~~~--~~--~--~---