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

  • Home
  • SEARCH
  • 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 9032583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:00:58+00:00 2026-06-16T08:00:58+00:00

I have created a layout with a database call where a button will be

  • 0

I have created a layout with a database call where a button will be created for each item inside the database. The buttons are created like I need and I also found out, how to set up the layout_width and layout_height but all buttons are placed in the same position and overlap each other so that only the last created button can be accessed. My code for creating the buttons looks like this:

Button bt = new Button(this);
bt.setText("Button Title");
bt.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
linerLayout.addView(bt);

The activity looks like that, after generating the buttons:

Overlapping buttons

I looked at each method that can be used for the button but didn’t find anything to define the position. I just thought about following method:

bt.layout(l, t, r, b);

but don’t know exactly how to use it and thought there might be a simpler method to solve this problem. Anybody who knows a workaround?!


CHANGED CODE

I just tryied to set the layout parameters like explained from "Chen doron". I have a relative layout inside my xml file:

<RelativeLayout
        android:id="@+id/llActOver"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="2" >        
</RelativeLayout>

and formatted the generated buttons like this:

Button bt = new Button(context);
bt.setText(c.getString(iDef));
fontClass.setFont(bt);
//RelativeLayout placeholder = new RelativeLayout(context);
RelativeLayout.LayoutParams  layoutParam = 
           new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                                           LayoutParams.WRAP_CONTENT);
if(rowCount < 1){
    layoutParam.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    rowCount++;
}else{
    layoutParam.addRule(RelativeLayout.ALIGN_PARENT_TOP, lastButtonId);
}

lastButtonId = bt.getId();
//placeholder.addView(bt, layoutParam);
        
linearLayout.addView(bt, layoutParam);

I save the buttons id at the end of the loop so that the last buttons id can be accessed in the next round.
I also tryied to create a new relativ layout for each new button like the commented part of the code shows but even without the new layout nothing happens and i still just have all buttons overlapped.

  • 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-16T08:00:59+00:00Added an answer on June 16, 2026 at 8:00 am

    I finally solved the problem, but just by trying each possible combination of layout types.
    I found out, i have to define a LinearLayout inside the XML file and the attribute android:orientation=”vertical” is affordable. all the other parameters that have been set before were unimportant.

    So now i have a LinearLayout inside a ScrollView in my xml file:

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="2" >
    
        <LinearLayout
            android:id="@+id/llActOver"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:orientation="vertical">
    
        </LinearLayout>
    </ScrollView>
    

    and inside the java database i have following code to create a button for each row in the db, setting its Text and Font and add it to the loaded layout:

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
    
        Button bt = new Button(context);
        bt.setText(c.getString(iDef));
        fontClass.setFont(bt);
        linearLayout.addView(bt);
    }
    

    and here a screenshot of the result:

    enter image description here

    maybe somebody else who has the same problem won’t need to worry as long as me with this description.

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

Sidebar

Related Questions

I have created the following database layout, and started coding the application. The more
I have created a simple layout using the HTML div tag. I would like
I have created a dynamic array of buttons that come from sqllite database. For
i am designing an app for android tablets. I have created a layout file
I have created two folders layout and layout-land with two xml files, one for
I have created a table layout in which my table row height is too
I created layout and layout-land folders, in Manifest i have android:configChanges=keyboardHidden|orientation If i remove
I have created an xml file like this: <?xml version=1.0 encoding=utf-8?> <ListView xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent
I'm using Drupal 6 and have created 2 equal columns in layout.css In the
I created one linear layout and I have added two relative layout. I wish

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.