Problems with LinearLayout and Button ad

Put your problem here if it does not fit any of the other categories.

Problems with LinearLayout and Button ad

Postby mihailo » Thu Mar 20, 2008 2:07 pm

Hello,

I'am trying to add an Dynamicly created Button to an pre-defined (xml) LinearLayout.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. LinearLayout lay = (LinearLayout) findViewById(R.id.content2);
  3.  
  4.      
  5.  
  6.         Button but = new Button(this);
  7.  
  8.         but.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  9.  
  10.         but.setText("Hallo");
  11.  
  12.        
  13.  
  14.         lay.addView(but);
  15.  
  16.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


but i get the error message : java.lang.IllegalArgumentException: Invalid LayoutParams supplied to android.widget.
LinearLayout@400b6c28.

What's wrong :cry: please help
mihailo
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Mar 20, 2008 1:51 pm

Top

Postby michael_g_hu » Fri Mar 21, 2008 9:55 am

I think you should use LinearLayout.LayoutParams as the params setting
michael_g_hu
Developer
Developer
 
Posts: 35
Joined: Fri Mar 21, 2008 9:46 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests