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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:06:32+00:00 2026-06-01T17:06:32+00:00

I have a dialog, which is created with this code: final Dialog dialog1 =

  • 0

I have a dialog, which is created with this code:

final Dialog dialog1 = new Dialog(Test.this);
dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog1.setContentView(R.layout.test_layout);
dialog1.setCancelable(true);
...

The layout file ‘test_layout.xml’ contains a typical TextView:

<TextView
    android:id="@+id/tv_username"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="10dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Test" />

I want in the code to set this TextView invisible (gone) in some cases.
I tried following:

TextView tv = (TextView) dialog1.findViewById(R.id.tv_username);
tv.setVisibility(TextView.GONE);

But the TextView still appears in the dialog. If I set in the layout xml file android:visibility=”gone” it is not appearing in the dialog. But I need to do it via code.

Here the whole code:

    if (whichButton == 1) {

           final Dialog dialog1 = new Dialog(Test.this);
                                       dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog1.setContentView(R.layout.test_layout);
            dialog1.setCancelable(true);

            TextView tv = (TextView) dialog1.findViewById(R.id.tv_username);
            tv.setVisibility(View.GONE);


        ...
        dialog1.show();
}

Here the whole XML file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="250dp"
    android:layout_height="match_parent"
>
    <TextView
        android:id="@+id/tv_name"
        android:paddingTop="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="15dp"
        android:textSize="14dp"
        android:text="Name:" />
    <EditText
        android:id="@+id/username"
        android:hint="@string/enterName"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:maxLength="15"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:scrollHorizontally="true"
        android:capitalize="words"
        android:singleLine="true"
        android:gravity="fill_horizontal"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    <TextView
        android:id="@+id/tv_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Test" />
    <TextView
        android:id="@+id/tv_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="15dp"
        android:textSize="14dp"
        android:text="@string/message" />
    <EditText
        android:id="@+id/tip"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:maxLength="290"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:scrollbars="vertical"
        android:inputType="textMultiLine"
        android:capitalize="words"
        android:gravity="fill_horizontal"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    <Button
        android:id="@+id/button"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/send_message" />
</LinearLayout>
  • 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-01T17:06:34+00:00Added an answer on June 1, 2026 at 5:06 pm

    I found a solution or workaround.

    The dialog was created in the the onClick method of an AlertDialog.

    Now I use the showDialog() method and handle it in the corresponding callback method.
    There it is working fine.

    I do not understand why this is working, but I only want to tell other users how they can solve this issue.

    I would be happy if someone can come up with a clarification.

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

Sidebar

Related Questions

hello all I have a small dialog which I created dynamically, which has a
I have created some code to popup a confirm dialog if a user tries
I have a form which instances a new form that I've already created using
I have a dialog which is used to create 2 sets of data which
I have an action which create QMessageBox. In that dialog I want to print
Introduction I have been so annoyed by applications that have a startup dialog which
I have 2 dialog boxes in which I will display 1 dialogbox at a
I have a list a simple dialog box which contains a few checkboxes, I
I'm coding an MFC application in which i have a dialog box with multiple
I have a very basic question. Scenario: 2 forms Form1, Form2- Dialog box which

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.