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 6070375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:55:35+00:00 2026-05-23T09:55:35+00:00

I am adding a button dynamically to a ListActivity. As follows: setContentView(R.layout.listview_singlegrey); LayoutInflater inflater

  • 0

I am adding a button dynamically to a ListActivity. As follows:

setContentView(R.layout.listview_singlegrey);
LayoutInflater inflater = (LayoutInflater)this.getSystemService
  (Context.LAYOUT_INFLATER_SERVICE);
LinearLayout linear = (LinearLayout) findViewById(R.id.list_comment);
Button btAddComment = (Button)inflater.inflate(R.layout.bt_yellow,null);
FrameLayout.LayoutParams lyp1 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
lyp1.gravity = Gravity.RIGHT;
btAddComment.setLayoutParams(lyp1);     
btAddComment.setText("Añadir comentario");

The LinearLayout for the listview is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent" android:orientation="vertical"
        android:layout_height="fill_parent" android:id="@+id/list_comment"
        android:paddingLeft="10dp" android:paddingRight="10dp" android:background="@drawable/fondomain">    
    <ListView android:id="@+id/android:list" android:listSelector="@android:color/transparent"
          android:layout_width="fill_parent" android:layout_height="fill_parent"
          android:divider="@layout/linedivider" android:dividerHeight="10px"
          android:cacheColorHint="#0000" android:paddingTop="10dp"           
          />
</LinearLayout>

And the layout of the button from where I am inflating is:

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
     style="@style/wrapfill"         
     android:background="@layout/selectoryellowbutton" android:layout_gravity="right" android:padding="10dp"
     android:textSize="16px" android:text="Añadir comentario" android:textStyle="bold" android:textColor="@color/darkergray">
</Button>

As you can see I have tried to set the layout_gravity params in the code and in the button, but none of them works. I still display the button on the left of the screen. It seems that the layout params are not working. But if I set fill_parent for the width I get the button all along the screen and I want the button wrapping the text and align to the right of the screen.

  • 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-05-23T09:55:35+00:00Added an answer on May 23, 2026 at 9:55 am

    your Button and ListView are contained in LinearLayout, android:layout_gravity attribute should be used with FrameLayout as parent view, don’t set FrameLayout.LayoutParams lyp1 as layout parameters for your button,

    try instead to set android:gravity="right" of your root LinearLayout or nest your button in another LinearLayout with gravity set to right, you could easily obtain button instance by calling findViewById on inflated layout later

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

Sidebar

Related Questions

In an Android ListActivity, I am adding a button as a footer in a
I'm adding a row like this, when a button is pressed. It must be
I'm dynamically adding rows/fields in this code. I have a text field for the
I am adding a spinner dynamically in a layout, as; public class FRQuestionsDetail extends
In my application i am adding the view dynamically to the linear layout. each
I'm having problems adding an event to a dynamically created element in Javascript. This
I am adding a button dynamically to HTML as shown below. When clicking that
i am creating a table layout with radio group by dynamically adding radiobuttons to
I'm interested in adding dividers to a LinearLayout's children dynamically. I see in the
I have code that works great for adding a button to the toolbar: NSArray*

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.