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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:52:35+00:00 2026-06-09T07:52:35+00:00

I have a problem with a custom dialog implemented as below: AlertDialog.Builder dialogBuilder =

  • 0

I have a problem with a custom dialog implemented as below:

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);

    dialogBuilder.setTitle("Title");
    dialogBuilder.setMessage("Message");

    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    // Set an EditText view to get user input
    EditText input = new EditText(this);
    input.setHeight(LayoutParams.WRAP_CONTENT);
    input.setWidth(LayoutParams.MATCH_PARENT);
    layout.addView(input);

    TextView text = new TextView(this);
    text.setText("show some text here");
    text.setHeight(LayoutParams.WRAP_CONTENT);
    text.setWidth(LayoutParams.MATCH_PARENT);
    //text.setHeight(50);
    //text.setWidth(150);
    text.setVisibility(TextView.VISIBLE);
    layout.addView(text);

    Button btn = new Button(this);
    btn.setText("Button");
    btn.setHeight(LayoutParams.WRAP_CONTENT);
    btn.setWidth(LayoutParams.WRAP_CONTENT);
    layout.addView(btn);

    dialogBuilder.setView(layout);
    dialogBuilder.setPositiveButton("Ok", null);

    AlertDialog myDialog = dialogBuilder.create();
    myDialog.show();

The problem is that the TextView text doesn’t show up in the dialog if I set its width and height as in the code above. It only appears if I hard code the properties (the two commented lines), but that’s not the desired behavior.

Also, although the Button has the width set as WRAP_CONTENT, it is as big as the screen.

Could someone please point out what I’m doing wrong here?

  • 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-09T07:52:37+00:00Added an answer on June 9, 2026 at 7:52 am

    You should use setLayoutParams() and not setHeight() and setWidth()

    Replace

    text.setHeight(LayoutParams.WRAP_CONTENT);
    text.setWidth(LayoutParams.MATCH_PARENT);
    

    With this

    text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    

    EDIT:
    About the Button use :

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

    It works to me…

    EDIT 2:
    If you use text.setHeight(LayoutParams.WRAP_CONTENT); it is equal to text.setHeight(-2); so your textView will be -2 pixel height and won’t be visible… on the other hands Buttons and other that uses a ninepatch image won’t get smaller than the ninepatch itself.

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

Sidebar

Related Questions

I have created a custom dialog, the code is below. The problem is that,
I have created a custom alertdialog by the following code: AlertDialog.Builder builder; AlertDialog alertDialog;
I have a problem with a custom dialog. My dialog consists of a TextView
I have a problem creating a custom dialog. But I don't find the failure.
here I have a custom dialog with background 2 ImageButton inside it. the problem
I have a little problem with an android custom dialog. I construct a custom
I have problem with casting custom event currentTarget to component. When I'm trying to
I have a problem with leaking custom cells. In my overridden UITableViewController, I have,
i have a list view with a BaseAdapter for custom view.. i have problem
I have a strange problem with my Custom View Group: It is an extended

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.