Antrromet
Antrromet

Reputation: 15414

EditText box not shown

I am trying to make a simple android application. I ma using the android version 2.3.3. I have used the following code for displaying a EditText box in my xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/username"
            android:textColor="#000000" />

        <EditText
            android:id="@+id/username"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:text="" >

            <requestFocus />
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/password"
            android:textColor="#000000" />

        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <CheckBox
            android:id="@+id/remember_me"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/remember_me"
            android:textColor="#000000" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button

            android:id="@+id/signInButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/signIn" >
        </Button>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll5"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/forgot_password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/forgot_password"
            android:textColor="#000000" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll6"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/createAccountButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/create_account" >
        </Button>
    </LinearLayout>

But the EditText is not being displayed. All other buttons, textviews and everything are being displayed properly, only the EditText are not being shown. Can anyone please tell me what the problem is??
-Thanks in advance

Upvotes: 2

Views: 9464

Answers (3)

Jayabal
Jayabal

Reputation: 3619

Its happens b'coz of the textview has width attribute as fill parent / match parent, so that the textview fill(width) the screen, then the edit text go out of visible area. to solve this follow the one of following method..

  1. set textview width as wrap_content or fixed width (ex 50dp). if u used wrap_content then again edit text may go out of visible area by depending on text in text view.

  2. set both text view and edit text's width as layout_width="match_parent" and add one more attribute layout_weight="1". now both text view and edit text equally share the share the width of parent.

        <TextView
            android:layout_width="match_parent" layout_weight="1"
            android:layout_height="wrap_content"
            android:text="@string/username"
            android:textColor="#000000" />
    
        <EditText
            android:id="@+id/username"
            android:layout_width="match_parent" layout_weight="1"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:text="" >
    
            <requestFocus />
        </EditText>
    </LinearLayout>
    

Upvotes: 1

Vinit ...
Vinit ...

Reputation: 1459

Give the id for TextView and put EditText below to the TextView

<TextView
android:id="@+id/testview1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/username"
    android:textColor="#000000" />

<EditText
    android:id="@+id/username"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
android:layout_below="@id/textview1"
    android:text=""
    android:inputType="text" >

Upvotes: 0

Ramesh Solanki
Ramesh Solanki

Reputation: 2926

please use this

<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
    android:orientation="horizontal" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:text="Name"
    android:textColor="#ffffff" />

<EditText   android:layout_weight="1"
    android:id="@+id/username"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:text="" >

    <requestFocus />
</EditText>

Upvotes: 4

Related Questions