Probably: new CheckBox (null) ==> new CheckBox (Dynamiclayout.this)
A log of the error you get would be more useful.. On Tue, Aug 24, 2010 at 6:25 PM, Sara Khalatbari <[email protected]>wrote: > Hi all > > I am trying to run the attached code to display a checkbox when I click on > the buttons. > > My program crashes though and I can not see why. > > Do you have any idea? > > Thank you, > Sara > > package Dynamiclayout.example.com; > > import Dynamiclayout.example.com.R; > import android.app.Activity; > import android.os.Bundle; > import android.view.View; > import android.widget.ScrollView; > import android.widget.LinearLayout; > import android.widget.Button; > import android.widget.CheckBox; > > public class Dynamiclayout extends Activity { > Button buttonGET,buttonPost; > CheckBox checkbox1; > LinearLayout ll = null; > > /** Called when the activity is first created. */ > @Override > > > public void onCreate(Bundle savedInstanceState) { > class clicker implements Button.OnClickListener { > @Override > public void onClick(View v) { > if(v==buttonGET){ > checkbox1 = new CheckBox (null); > checkbox1.setText("I'm dynamic!"); > ll.addView(checkbox1); > } > if(v==buttonPost){ > checkbox1.setText("I'm very dynamic!"); > ll.addView(checkbox1); > > } > } > } > > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > ScrollView sv = new ScrollView(this); > //LinearLayout ll = new LinearLayout(this); > ll = new LinearLayout(this); > ll.setOrientation(LinearLayout.VERTICAL); > sv.addView(ll); > > buttonGET = new Button(this); > buttonGET.setText("GET"); > ll.addView(buttonGET); > buttonGET.setOnClickListener(new clicker()); > > buttonPost = new Button(this); > buttonPost.setText("POST"); > ll.addView(buttonPost); > buttonPost.setOnClickListener(new clicker()); > > this.setContentView(sv); > > > } > } > > -- > 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]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- YuviDroid Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a widget to quickly access your favorite apps and contacts!) http://android.yuvalsharon.net -- 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] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

