Android - Problem of WrapText in Edittext - android

I am facing trouble to set WrapText kind of facility in EditText.
Problem: When i try tp enter data in EditText, it goes beyond the screen width (scrolling horizontally). Instead of it should be appear in next-line.
Want to perform: Actually, i want to implement multiline edittext, initially it should display with single-line as usual, but it will be expanded vertically(not horizontally) as when data is being entered.
Please suggest me what should i do ??
Please have a look at below image:
I have done the below XML coding:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:stretchColumns="1">
<TableRow android:id="#+id/TableRow02" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView
android:text="Name:"
android:id="#+id/TextView01"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:textSize="16dip">
</TextView>
<EditText
android:id="#+id/txtViewName"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="textFilter|textMultiLine|textNoSuggestions"
android:scrollHorizontally="false">
</EditText>
</TableRow>
</TableLayout>

You can try to change the width to fill_parent.

try adding following code in your edit text if you want to wrap it in a single line:
android:singleLine="true"
OR set the width of your edittext to fill_parent or any value in dip if you want multiline.

I just change this: android:layout_width ="0dip" and it is working fine.
Multiline edittext but initially it is being displayed one line, it will be expanded vertically(not horizontally) as and when the more and more data are being entered.

Just use both android:stretchColumns="1" and android:shrinkColumns="1" instead the only one android:stretchColumns="1":
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:stretchColumns="1"
android:shrinkColumns="1">

I've tested it on a 2.1 emulator enclosing the code (with fill_parent in the edit text) inside this relative layout and appears to be ok.
<?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="fill_parent"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:stretchColumns="1">
<TableRow android:id="#+id/TableRow02" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView
android:text="Name:"
android:id="#+id/TextView01"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:textSize="16dip">
</TextView>
<EditText
android:id="#+id/txtViewName"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="textFilter"
android:scrollHorizontally="false">
</EditText>
</TableRow>
</TableLayout>
</RelativeLayout>
Maybe you can navigate the xml tree in the eclipse outline window and see what view is bigger than the screen.

Related

scroll view inside scroll layout?

i need your help. Basically I created a scrollView as a parent layout of an activity . Now i need to add many widgets inside the activity including an edittext containing large text values set inside this edittext which is also scrollable , but my text inside an edit text not scrolling smoothly? i need text area like widgets , my xml code shown below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#498BF4">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Registration"
android:gravity="center_horizontal"
android:textSize="20dip"/>
</LinearLayout>
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="User_id:*"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dip"
android:id="#+id/user">
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="FirstName:*"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dip"
android:id="#+id/fname">
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="LastName:*"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dip"
android:id="#+id/lname">
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Email:*"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dip"
android:id="#+id/email">
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Currency:*"
android:textSize="15dip"/>
<Spinner
android:id="#+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="40dip">
</Spinner>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Date of Birth:*"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dip"
android:id="#+id/dob">
</EditText>
<LinearLayout
android:id="#+id/agepermission"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="gone">
<EditText
android:layout_width="fill_parent"
android:layout_height="150dip"
android:id="#+id/ageterms"
android:maxLines="10"
android:textSize="10dip"
android:text="#string/hello"
>
</EditText>
<CheckBox
android:text="I have permission to use the website from parent/guardian.*"
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Parent Name:*"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dip"
android:id="#+id/pname">
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Parent Email:*"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dip"
android:id="#+id/pemail">
</EditText>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Terms and conditions:*"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="200dip"
android:id="#+id/terms"
![android:text="i need your help. Basically I created a scrollView as a parent layout of an activity . Now i need to add many widgets inside the activity including an edittext containing large text values set inside this edittext which is also scrollable , but my text inside an edit text not scrolling smoothly? i need text area like widgets i need your help. Basically I created a scrollView as a parent layout of an activity . Now i need to add many widgets inside the activity including an edittext containing large text values set inside this edittext which is also scrollable , but my text inside an edit text not scrolling smoothly? i need text area like widgets i need your help. Basically I created a scrollView as a parent layout of an activity . Now i need to add many widgets inside the activity including an edittext containing large text values set inside this edittext which is also scrollable , but my text inside an edit text not scrolling smoothly? i need text area like widgets i need your help. Basically I created a scrollView as a parent layout of an activity . Now i need to add many widgets inside the activity including an edittext containing large text values set inside this edittext which is also scrollable , but my text inside an edit text not scrolling smoothly? i need text area like widgets"][2]
android:inputType="textMultiLine"
android:textSize="10dip"
>
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="By clicking on 'Sign Up' button below you are agreeing to the Terms of Service above and both the Program Policy and the Privacy Policy."
android:textSize="15dip"/>
<Button
android:text="Sign Up"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="40dip"
>
</Button>
</LinearLayout>
</ScrollView>
</LinearLayout>
use below tag in your edittext , if it input is multiline
android:inputType="textMultiLine"
I am having the same problem here.
So far I know the only solution is to disable the scrolling of the ScrollView when the EditText got focus.

Make a component fill all available space on screen

I want something like this:
But I don't know how to resize the TextView so it gets all the available space on screen which is not ocuppied by the EditText or the Buttons. May I do it in the code, or in the xml?
At XML I tried putting the TextView into a FrameLayout, but it makes no difference. Currently looks like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/consola"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars = "vertical"
android:text="#string/hello"/>
</FrameLayout>
<EditText
android:id="#+id/comando"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="Conectar"
android:id="#+id/boton_conectar"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</Button>
<Button
android:text="Enviar"
android:id="#+id/boton_enviar"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
</LinearLayout>
At the code I'm just checking if the Buttons are pushed with Listeners. One of them, when pushed, gets the text at the EditText, and appends it to the TextView. It works, and TextView gets higher, while EditText and Buttons downs one line. If I go on appending lines, finaly EditText and Buttons get out of the screen. I want to avoid this behaviour, and accomplish to get this 3 widgets sticked to the bottom of the screen.
Use the android:layout_weight=1 attribute, like the buttons on the bottom of the form. That will assign most of the space to it and anything that's left to the rest of the elements.
It's all about the weight. This should give you what you want:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:text="TextView"
android:id="#+id/textView1"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</TextView>
<EditText android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<requestFocus></requestFocus>
</EditText>
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:text="Button"
android:id="#+id/button1"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp">
</Button>
<Button android:text="Button"
android:id="#+id/button2"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
(Side note: When using weight, setting the corresponding height/width to 0dp sometimes gets around some weird behavior.)
Try android:fillViewport="true".

How can I layout two buttons to be the same size?

The layout definition is below. Basically I want the two buttons to be the same width, but right now their width is determined by the string they display, is there a better way to lay this out such that the buttons are the same width and that the Button+EditText combo fills the width of the screen?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/editorlinearlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="#+id/setNameBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Set Item Name "/>
<EditText android:id="#+id/nameTxtBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="#+id/setGroupBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Group Name"/>
<EditText android:id="#+id/groupTxtBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
Edit:
I've tried using a TableLayout as was suggested below, but now the EditText's don't fill the remaining portion of the screen. See the image and layout below.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<Button android:id="#+id/setNameBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Set Item Name "/>
<EditText android:id="#+id/nameTxtBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow>
<Button android:id="#+id/setGroupBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Group Name"/>
<EditText android:id="#+id/groupTxtBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
the trick is to combine the tableview defined in the edit above with a strechColumn tag:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
<Button android:id="#+id/setNameBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Set Item Name "/>
<EditText android:id="#+id/nameTxtBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
Use a TableLayout and TableRows.
Three options:
Put this in a TableLayout instead of the nested LinearLayout thing you are currently doing
Change your nesting from a vertical parent with horizontal children to a horizontal parent with vertical children (however, this opens up possible vertical positioning issues, so I don't favor this option)
Use a RelativeLayout and all of the layout_* attributes that RelativeLayout children have available to them
I'd favor option 1, personally.
you can use specific width and height for laout_width/layout_height, as in layout_width="150dip". You run the risk of having a button that can't fit all your text though, but if your text is fixed, you can double check to make sure it's all good.

Android: EditText not filling ScrollView and RelativeLayout

I have been trying to wrap my editText with ScrollView to auto scroll it when the content is updated. I found the problem that the EditText wont cover the entire scroll view even with both width and height are set to fill_parent. Please enlighten me. Thank you.
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="send"
/>
<EditText
android:id="#+id/msgBox"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/sendButton"
android:gravity="left"
android:longClickable="false"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/msgBox">
<EditText
android:id="#+id/chatBox"
android:editable="false"
android:gravity="left|top"
android:cursorVisible="false"
android:longClickable="false"
android:clickable="false"
android:autoLink="all"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</ScrollView>
</RelativeLayout>
Try adding android:fillViewport="true" to ScrollView properties. That should make it adjust its size every time something inside it changes. Also, use android:layout_height=wrap_content for EditText. It doesn't make sense to fill a parent that itself can re-size

Nesting Relative layout inside Linear Layout

I have the following code in my layout.xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent">
<EditText android:hint="#string/feed_url"
android:id="#+id/feedUrl" android:textSize="14dp" android:inputType="textUri"
android:layout_marginRight="45dp" android:layout_height="wrap_content" android:layout_width="fill_parent">
</EditText>
<Button android:id="#+id/getGraph"
android:text="#string/get"
android:layout_toRightOf="#id/feedUrl"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" android:width="45dp" android:layout_width="wrap_content">
</Button>
</RelativeLayout>
<WebView android:id="#+id/wv1" android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
In the eclipse Plugin layout creator, the EditText and button are shown properly. (see the below screenshot)
But on the device and emulator, the button is not hidden. (see the below screenshot)
Any idea why the button is getting hidden in the device?
Try the following changes to your code. You have to define the button first, since it is of fixed width, and then place the EditText to fill the rest of the space, placed to the left of the button. The button also has to be defined first (prior to Android 2.2, that is).
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button
android:id="#+id/getGraph"
android:text="#string/get"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<EditText
android:hint="#string/feed_url"
android:id="#+id/feedUrl"
android:textSize="14dp"
android:inputType="textUri"
android:layout_marginRight="45dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toLeftOf="#id/getGraph"
/>
</RelativeLayout>
I cannot see the button in the layout builder... the reason, I think is that the EditText width is fill parent so it fills parent pushing the button out. If you must use RelativeLayout, you need to define width of the EditText explicitly. Otherwise you may want to switch to horizontal LinearLayout and set weight of the edit box to "1".
Also, there are invalid options for RelativeLayout:
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal
You can also use LinearLayout instead of RelativeLayout to archive this. You can use android:layout_weight to make Button not be overlaid by EditText. Following is the sample xml that may work:
<LinearLayout android:orientation="horizontal"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<EditText android:hint="#string/feed_url"
android:id="#+id/feedUrl" android:textSize="14dp"
android:inputType="textUri" android:layout_marginRight="45dp"
android:layout_height="wrap_content" android:layout_width="fill_parent" />
<Button android:id="#+id/getGraph" android:text="#string/get"
android:layout_height="wrap_content" android:width="45dp"
android:layout_width="wrap_content"
android:layout_weight="1" />
</LinearLayout>

Categories

Resources