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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:37:06+00:00 2026-05-31T15:37:06+00:00

I’m creating an alertDialog to ask for a login data. I would like to

  • 0

I’m creating an alertDialog to ask for a login data.

I would like to use all the horizontal space, but I can’t get it:

AlertDialog.Builder loginData = new AlertDialog.Builder(activity);
    loginData.setTitle("Tus datos");
    LinearLayout layout = new LinearLayout(activity);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    LinearLayout linea1 = new LinearLayout(activity);
    linea1.setOrientation(LinearLayout.HORIZONTAL);

    linea1.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, 
            ViewGroup.LayoutParams.WRAP_CONTENT));

    final TextView Usuario = new TextView(activity);
    Usuario.setText("Usuario");
    linea1.addView(Usuario);

    final EditText usuario = new EditText(activity);
    linea1.addView(usuario);

    layout.addView(linea1);
    // Set an EditText view to get user input

    LinearLayout linea2 = new LinearLayout(activity);
    linea2.setOrientation(LinearLayout.HORIZONTAL);

    linea2.setLayoutParams(new ViewGroup.LayoutParams(
           ViewGroup.LayoutParams.FILL_PARENT,
           ViewGroup.LayoutParams.WRAP_CONTENT));

    final TextView Contrasena = new TextView(activity);
            Contrasena.setText("Contraseña");
            linea2.addView(Contrasena);

    final EditText contrasena = new EditText(activity);
            linea2.addView(contrasena);

    layout.addView(linea2);

    loginData.setView(layout);

    loginData.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

                    try{
                      //do the work 
                    } catch (Exception e){
                        e.printStackTrace();
                    }

                }
            });

    loginData.show();   
}

How can I do it?

  • 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-31T15:37:07+00:00Added an answer on May 31, 2026 at 3:37 pm

    Try:

         ..... 
         usuario.setLayoutParams(new ViewGroup.LayoutParams(
                      ViewGroup.LayoutParams.FILL_PARENT,
                      ViewGroup.LayoutParams.WRAP_CONTENT));
         .....
         contrasena.setLayoutParams(new ViewGroup.LayoutParams(
                      ViewGroup.LayoutParams.FILL_PARENT,
                      ViewGroup.LayoutParams.WRAP_CONTENT)); 
         .....
    

    But in my opinion – you should use xml for layout.

    dialog.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
    
    <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="1"
            >
        <TableRow>
            <TextView
                    android:id="@+id/label1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Usuario"
                    />
            <EditText
                    android:id="@+id/text1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    />
        </TableRow>
        <TableRow>
            <TextView
                    android:id="@+id/label2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Contraseña"
                    />
            <EditText
                    android:id="@+id/text2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    />
        </TableRow>
    </TableLayout>
    

    In activity:

       ....
        LayoutInflater inf = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inf.inflate(R.layout.dialog, null);
    
        AlertDialog.Builder loginData = new AlertDialog.Builder(this);
        loginData.setTitle("Tus datos");
        loginData.setView(layout);
        loginData.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
    
                try{
                    //do the work
                } catch (Exception e){
                    e.printStackTrace();
                }
    
            }
        });
    
        loginData.show();
    
       .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
I would like to run a str_replace or preg_replace which looks for certain words
I want to construct a data frame in an Rcpp function, but when I
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

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.