user2072218
user2072218

Reputation: 1

android app development simple messaging app

I use the following main.xml code but I can only see one edit text box

I need help regarding why does this occur? I have tried many times but I cannot see proper edit box and all other components

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

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

    android:text="ENTER THE PHONE NUMBER HERE" />

<EditText 
    android:id="@+id/txtPhoneNo"  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"        
    />
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"         
    android:text="Message"
    />     
<EditText 
    android:id="@+id/txtMessage"  
    android:layout_width="fill_parent" 
    android:layout_height="150dp"
    android:gravity="top"         
    />          
<Button 
    android:id="@+id/btnSendSMS"  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:text="Send SMS"
    />    

Upvotes: 0

Views: 139

Answers (2)

codeMagic
codeMagic

Reputation: 44571

This is because you haven't set an orientation for your LinearLayout and the default is horizontal. Since you have all of your views width set to fill_parent, there is no room for the others

You have a couple options. You can either set

android:orientation="vertical"

in your root LinearLayout or you can change the width of these views

android:layout_width="wrap_content"

There are other ways too, obviously, but these are the easiest fixes for what you have

LinearLayout Docs

Also Note:

FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)

Layout Params

Side Note

I see you are using hard-coded strings in your xml. Eclipse will warn you about this and it may give you headaches in the future if you don't get accustomed to using the strings.xml folder and using the android:text="@string/string_name"

Strings

Upvotes: 1

Dany Pop
Dany Pop

Reputation: 3648

On your LinearLayout check the orientation=vertical

Upvotes: 0

Related Questions