Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:42:36+00:00 2026-06-04T19:42:36+00:00

I am making a simple soundboard app – buttons should appear in two columns,

  • 0

I am making a simple soundboard app – buttons should appear in two columns, pressing a button plays a sound. I made it and had all the buttons defined using XML and it worked fine, but since the app was already attaching a listener to play a sound using a loop, I decided to define the buttons using only code.

So the code has no errors and the app launches but no buttons appear. There is a similar problem here: Content not showing in dynamically created android TableLayout although if I understand it correctly, the proposed solution (ensure Im using TableLayout.LayoutParams) is already applied here.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main_table2);

    int[] sounds = { ... };

    String[] labels = { ... };

    declareButtons(sounds, labels);
}

private void declareButtons(int[] sounds, String[] labels)
{
    TableLayout tbl = (TableLayout) this.findViewById(R.id.tblMain);
    TableRow row = null;
    Button cell;

    for (int i=0; i<sounds.length; i++)
    {
        cell = new Button(this);
        cell.setText(labels[i]);
        cell.setOnClickListener(this.getStartListener(sounds[i]));

        cell.setBackgroundDrawable(getResources().getDrawable(R.drawable.soundbutton));
        cell.setTextColor(color.white);
        TableLayout.LayoutParams cellParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, (float) 1);
        cellParams.leftMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());
        cellParams.topMargin = cellParams.leftMargin;

        if (i%2==0) // left column
        {
            row = new TableRow(this);
            cell.setLayoutParams(cellParams);
            row.addView(cell);
        }
        else // right column
        {
            cellParams.rightMargin = cellParams.leftMargin;
            cell.setLayoutParams(cellParams);
            row.addView(cell);
            row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
            tbl.addView(row);
        }
    }

    if (sounds.length%2 > 0) // handle uneven amount of buttons
        tbl.addView(row);
}

And here is the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/leonbg2"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableLayout
            android:id="@+id/tblMain"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >


        </TableLayout>
    </ScrollView>

</LinearLayout>

Here is how table rows were defined previously, which worked fine:

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <Button
                android:id="@+id/buttonaw"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:layout_weight="1"
                android:background="@drawable/soundbutton"
                android:text="A what?"
                android:textColor="@android:color/white" />

            <Button
                android:id="@+id/buttona"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:layout_weight="1"
                android:background="@drawable/soundbutton"
                android:text="Argh!"
                android:textColor="@android:color/white" />
        </TableRow>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:42:38+00:00Added an answer on June 4, 2026 at 7:42 pm

    Well, I managed to fix it myself by getting rid of TableLayout and going for a bunch of LinearLayouts (one for each row). The code is more or less the same with the addition of row.setOrientation(LinearLayout.HORIZONTAL); before cell.setLayoutParams(cellParams); in the left column part of the if statement. The moral of the story is; if you think you need to use TableLayout, you probably dont. Peace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to change sizes of ViewController? I'm making simple app which uses deliberately two
Making a simple map app, plan on adding buttons to mark specific locations But
I'm making a simple hobby piece that simply contains two buttons. When I try
I am making simple connection between two table - first one called users has
I'm making a simple reading canvas app, and I want to be ale to
Im making a simple app for some friends to use on there android phone
I am making this simple get request using jquery ajax: $.ajax({ url: https://app.asana.com/-/api/0.1/workspaces/, type:
To learn WP7 i'm making a simple soundboard application. This is my code. Please
I'm making a simple class that uses operator<< . It will store two parallel
Iam making a simple app, I display pdf file with some text and images

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.