1

I have a table layout wher i am displaying values from my database i have seven columns for that table.. i am adding rows to the table layout programmatically adding the data is fine..m doing that by using textviews..but in my seventh column i need to add two buttons..i need the two buttons in the same column and one beside the other....m able to display only one button..how do i display two buttons in one row in the same column??? Is it possible to do that?? Please help!! Thanks!

Here's how i am adding rows programmatically:

do
        {
            tr=new TableRow(this);
            tr.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));

            firstCol=new TextView(this);
            firstCol.setText("0");
            firstCol.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
            firstCol.setGravity(Gravity.CENTER);
            tr.addView(firstCol);

            secondCol=new TextView(this);
            secondCol.setText(lead.getString(index0));
            secondCol.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
            secondCol.setGravity(Gravity.CENTER);
            tr.addView(secondCol);

            thirdCol=new TextView(this);
            thirdCol.setText(lead.getString(index1));
            thirdCol.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
            thirdCol.setGravity(Gravity.CENTER);
            tr.addView(thirdCol);

            fourthCol=new TextView(this);
            fourthCol.setText(lead.getString(index2));
            fourthCol.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
            fourthCol.setGravity(Gravity.CENTER);
            tr.addView(fourthCol);

            fifthCol=new TextView(this);
            fifthCol.setText(lead.getString(index3));
            fifthCol.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
            fifthCol.setGravity(Gravity.CENTER);
            tr.addView(fifthCol);

            sixthCol=new TextView(this);
            sixthCol.setText(lead.getString(index4));
            sixthCol.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
            sixthCol.setGravity(Gravity.CENTER);
            tr.addView(sixthCol);

            seventhCol=new Button(this);
            seventhCol.setBackground(getApplicationContext().getResources().getDrawable(R.drawable.circ));
            tr.addView(seventhCol);

            lead_table.addView(tr);

            tr.setOnClickListener(this);

        }while(lead.moveToNext());

Here is the table layout:

 <TableLayout
        android:id="@+id/lead_table"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="50dp"
        android:gravity="center"
        android:stretchColumns="*" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@drawable/bgbtn"
                android:paddingLeft="30dp"
                android:text="Lead ID"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bgbtn"
                android:paddingLeft="15dp"
                android:text="Name"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bgbtn"
                android:paddingLeft="20dp"
                android:text="Mobile"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bgbtn"
                android:paddingLeft="15dp"
                android:text="Product"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bgbtn"
                android:paddingLeft="15dp"
                android:text="Value"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bgbtn"
                android:paddingLeft="15dp"
                android:text="Status"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bgbtn"
                android:paddingLeft="15dp"
                android:text="Action"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </TableRow>


    </TableLayout>
4
  • Think logically, How can you display 2 buttons in the same column in one row, if you want to let them be displayed side by side ? It does not make any logical sense. You can how ever, keep 2 buttons in two different columns in the same row and display them as side by side entities . Commented Jun 13, 2013 at 10:16
  • @TheDarkKnight but i have a header for that column and those two buttons need to cum under that column!
    – shivani
    Commented Jun 13, 2013 at 10:18
  • Okay, so what you have to do here is add two columns inside that column and then add the buttons to those columns. Let me try that . I will get back to you . Or you can follow Torben's solution as well, that will work also, i assume . Commented Jun 13, 2013 at 10:24
  • Post your activity_main.xml , so that we can see the table layout Commented Jun 13, 2013 at 10:27

1 Answer 1

5

Create a LinearLayout, add the two buttons to it and then add the LinearLayout to the TableRow.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.