1. Are you ready for the Galaxy S20? Here is everything we know so far!

Table layout programatically

Discussion in 'Android Development' started by pecmcrl, Sep 1, 2011.

  1. pecmcrl

    pecmcrl Lurker
    Thread Starter

    Hi.......i am new to android development.. Iam trying to create a table layout programatically in the activity it self without using xml file........ Please help to know can i do it.

    Can anyone find the error in following code.....

    import android.app.Activity;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.TableLayout;
    import android.widget.TableRow;
    import android.widget.TextView;

    public class Tablelayout extends Activity{
    public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    LayoutParams params=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);

    TextView tv=new TextView(this);
    tv.setLayoutParams(params);
    tv.setTextColor(Color.RED);

    TableRow tr=new TableRow(this);
    tr.addView(tv);

    TableLayout tl=new TableLayout(this);
    TableLayout.LayoutParams layoutparams=new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    tl.addView(tr);

    this.addContentView(tl, layoutparams);
    }
    }
     



    1. Download the Forums for Android™ app!


      Download

       
  2. miXer

    miXer Android Enthusiast

    Is the app crashing? Try to explain some more. If the app is crashing, look in logcat to see what exception is beeing thrown.
     
  3. pecmcrl

    pecmcrl Lurker
    Thread Starter

    While running its showing error like "the application has stopped unpectedly. please try again" and the logcat showing runtime error message at dalvik.system.NativeStart.man(Native method)
     
  4. miXer

    miXer Android Enthusiast

    Pasting the whole exception would be of good help
     
Loading...

Share This Page

Loading...