1

I have used a TableLayout to display data. Data is in json format so for that I have created dynamic TableRow and TextView with filled data and putted into the TableLayout. In test application I have taken a fix string array to filled the table in place of json. It doesn't matter.

The problem is that all code runs well without error. Even I have debug each line of code. I didn't find any error. Event then My data is not showing in a table. TableLayout remains blank as in starting. My code is:

    @Override
public void onCreate(Bundle savedInstanceState) {
    try
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabular_layout);        
        final TableLayout tl = (TableLayout)findViewById(R.id.tblLyt);

        for(int i = 0; i<names.length; i++)
        {

            TableRow tr = new TableRow(this);               
            TextView tv1 = new TextView(this);
            TextView tv2 = new TextView(this);

            createView(tr, tv1, Integer.toString(i+1));
            createView(tr, tv2, names[i]);

            tl.addView(tr);             
        }

    }
    catch(Exception ex)
    {
        MessageBox(ex.getMessage());
    }
}

public void createView(TableRow tr, TextView t, String viewdata) throws Exception{
    try
    {
        t.setText(viewdata);
        t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        t.setTextColor(Color.DKGRAY);
        t.setBackgroundColor(Color.WHITE);
        t.setPadding(20, 0, 0, 0);
        tr.setPadding(0, 1, 0, 1);
        tr.addView(t); // add TextView to row.
    }
    catch(Exception ex)
    {
        throw ex;
    }
}

This is my tabular_layout.xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" android:weightSum="1">
       <TableLayout android:layout_width="fill_parent" android:id="@+id/tblLyt"       android:layout_height="wrap_content" android:layout_weight="0.69">             
       </TableLayout>

   </LinearLayout>

I am still new in Android. I might done silly mistake. But I tried a lot on this and also searched for that. So help me !!

Thanks.

4
  • Basically what kind of UI layout wants? if possible then put an example snap, so that anyone can suggest easily. Commented Jul 13, 2011 at 7:04
  • @PM - As I told I used a TableLayout and in that am adding a TableRow and Textview for holding data. all goes well without error. But still data is not displayed. Commented Jul 13, 2011 at 7:11
  • Post your tblLyt.xml. Problem is there.Your code is okay Commented Jul 13, 2011 at 7:17
  • @Rasel: I have added xml code in above. Commented Jul 13, 2011 at 7:31

2 Answers 2

1

Problem is in the following line.block it and run your program

t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

Sign up to request clarification or add additional context in comments.

1 Comment

Accepting/Upvoting the answer is the best way of thanking,I think.
0

/** * You need to return tablerow and hold in mainlayout. use below code /

public TableRow createView(TableRow tr, TextView t, String viewdata) throws Exception{ try { t.setText(viewdata); t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); t.setTextColor(Color.DKGRAY); t.setBackgroundColor(Color.WHITE); t.setPadding(20, 0, 0, 0); tr.setPadding(0, 1, 0, 1); tr.addView(t); // add TextView to row. } catch(Exception ex) { throw ex; }

retuen tr; }

// call like dynamica layout tl.addView(createView(tr, tv1, Integer.toString(i+1));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.