Position an element below a multiline EditText - android

I have a list of data displayed as , one below the other:
name James
phone 032-432-4556
street line 1
line 2
etc.
email me#my.com
The most logical (I guess) is to position the email below the street , as the edittext is variabel in length and left align it with previous textviews. Whichever combination of layout params I've tried, "Email" remains immediatly below the "street" label. Even the margin is not respected. Who knows the correct combination of layout params and referred to items?
This is my layout and below it the screen as it shows:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".DisplayContact" >
<RelativeLayout
android:id="#+id/oneContact"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/textTextName"
.............
<EditText
android:id="#+id/editTextName"
.............
</EditText>
<TextView
android:id="#+id/textTextPhone"
.............
<EditText
android:id="#+id/editTextPhone"
.............
<TextView
android:id="#+id/textTextStreet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textTextPhone"
android:layout_alignLeft="#id/textTextName"
android:layout_alignStart="#id/textTextName"
android:layout_marginTop="#dimen/field_vertical_margin"
android:text="#string/street"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextStreet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/textTextStreet"
android:layout_alignLeft="#id/editTextName"
android:layout_alignStart="#id/editTextName"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
android:id="#+id/textTextEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editTextStreet"
android:layout_alignLeft="#id/textTextName"
android:layout_alignStart="#id/textTextName"
android:layout_marginTop="#dimen/field_vertical_margin"
android:text="#string/email"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/textTextEmail"
android:layout_alignLeft="#id/editTextName"
android:layout_alignStart="#id/editTextName"
android:ems="10"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/textTextCity"
.............
<EditText
android:id="#+id/editTextCity"
.............
</RelativeLayout>

I recommend using a vertical LinearLayout as your root, instead of RelativeLayout and creating a layout as described here Android: creating two columns in a linearlayout
You can also try a Table https://developer.android.com/guide/topics/ui/layout/grid.html.

Related

Unable to add new line in EditText android

I am creating a view where the user can enter text like a notepad and when user presses ENTER, the cursor will go to the next line. I have tried many configurations with EditText by exploring inputType, imeOptions maxLines etc. with no luck.
The text always stays in a single line. If the line length is more than the view, it simply grows to the right.
Is there a way to make sure the EditText
Accepts new lines and display text with line breaks?
Wraps to the width of the container
<LinearLayout
android:id="#+id/container_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:gravity="top"
android:layout_above="#+id/button_box">
<TextView
android:id="#+id/act_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text= "April 12, 2015 2:45 PM"
android:paddingBottom="4dp"
android:textColor="?attr/attrColorNewEntryChangedDate"
android:gravity="center"
android:visibility="gone"/>
<View
android:id="#+id/act_change_date_border"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="?attr/attrColorBorder"
android:visibility="gone"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:inputType="textMultiLine"
android:imeOptions="actionNone"
android:ems="10"
android:id="#+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:layout_marginBottom="50dp"
/>
</LinearLayout>
you can try this
android:layout_width="wrap_content"
android:maxLines="3"

Android EditText box and cursor/text moving around

I have an android application that has 3 EditText widgets. When I enter values, everything is fine. When I click a button, the cursor and/or text like falls below the line as shown in the images. I can click and drag the text/cursor up and down (like it was a date chooser or something). This does happen on all 3 fields. This happens on a device, and in an emulator.
I do not recall changing any properties on those widgets that could cause this, and such, examining all the properties does not shed any light on what would cause it. Even if there are not any values, such as the the discount field, I can move the hint text just like I can move the user entered values. I thought perhaps it had something to do what I was doing with onClickListenener, but I do not change anything there. I can choose a selection from the overflow menu and it happens there too. Any ideas on why this is happening?
The XML for the field:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_calc">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:id="#+id/tableLayout">
<TableRow
android:layout_width="fill_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/etxtPrice"
android:layout_column="1"
android:textAlignment="center"
android:hint="Price"/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/etxtDiscount"
android:layout_column="2"
android:textAlignment="center"
android:hint="Discount" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%"
android:id="#+id/textView"
android:layout_column="3"
android:textSize="20dp" />
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/etxtTax"
android:layout_column="4"
android:textAlignment="center"
android:hint="Tax" />
</TableRow>
Since the height of the edittext is wrap_content.. the edit text can accommodate any number of lines of text. Use android:singleLine="true" attribute to force it to single line.

TextViews inside ListView only shows the first word in a string with space infrequently

In a dialog I have a listview with multiple textviews. Problem is it inconsistently truncates the value after auto for some textview if I shuffle the pattern is different again. But never once all the textview displayed the entire text.
I couldn't understand why it is happening and not sure what other combination of values it might truncate. I have tried it with other values with spaces and it showed up correctly but right now it is creating problem in "auto" words only. Even tried it with UPPERCASE but still same results.
ListView layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioButton
android:id="#+id/radioBtncustomerAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="10dp"
android:text="Address Type"
android:gravity="top"
android:checked="false"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="50dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textviewcustomershipbilladdress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address" />
<TextView
android:id="#+id/textviewcustomershipbillstreet"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<requestFocus />
</TextView>
<TextView
android:id="#+id/textviewcustomershipbillarea"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/textviewcustomershipbillcity"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/textviewcustomershipbillstate"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/textviewcustomershipbillcountry"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/textviewcustomershipbillpincode"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/textviewcustomershipbilldistrict"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
Code in ListView Adapter
holder.text1.setText("auto street");
holder.text2.setText("auto add");
holder.text3.setText("auto district");
holder.text4.setText("auto pin");
holder.text5.setText("auto area");
holder.text6.setText("auto country");
holder.text7.setText("auto city");
holder.text8.setText("auto state");
DISPLAY
auto street
auto add
auto
auto pin
auto area
auto
auto city
auto state
Simply make your inner Linear Layout width to be match_parent , its working fine then
<LinearLayout
android:layout_width="match_parent"<!--Set it to me match_parent-->
android:layout_height="match_parent"
android:layout_marginLeft="50dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:orientation="vertical" >

Layout won't expand with EditText

When I type into the EditText box, the RelativeLayout containing it does not expand. The problem is I want it to.
Here's a visual display of the problem:
There's about 5 lines of gibberish typed in there and you can see the 2nd to last line cut off. Up to a maximum of 5 lines should be showing, but they're not, most likely because they're inside a layout whose height is set to wrap the contents. How can I make the parent layout expand when the EditText expands?
Here is the problem xml displaying the message box you see in the picture:
<RelativeLayout
android:id="#+id/group_chat_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:background="#drawable/transparent_background2" >
<TextView
android:id="#+id/send_msg_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/transparent_background2"
android:text="Send" />
<EditText
android:id="#+id/group_chat_input_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBottom="#id/send_msg_button"
android:layout_toLeftOf="#id/send_msg_button"
android:background="#00000000"
android:hint="Type a message..."
android:textColorHint="#EEEEEE"
android:inputType="textMultiLine"
android:maxLines="5"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:shadowColor="#000000"
android:shadowRadius="3"
android:shadowDx="3"
android:shadowDy="3"/>
</RelativeLayout>
How can I make the parent layout expand when the EditText expands?
This isn't working because the EditText is anchored to the TextView with
android:layout_alignBottom="#id/send_msg_button"
The EditText is trying to expand down but it can't since it isn't allowed to go below that point.
Removing this and anchoring it to the top of the TextView will solve that issue but creates other problems with the placement of the TextView if the EditText grows too much.
I've tested some of my suggestions from comments and it seems to give what you want. You will find my example below with some changes in bg and colors just to work with my test project.
<RelativeLayout 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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/group_chat_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:background="#drawable/abc_item_background_holo_dark" >
<TextView
android:id="#+id/send_msg_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="#id/group_chat_input_box"
android:background="#drawable/abc_item_background_holo_light"
android:text="Send" />
<EditText
android:id="#+id/group_chat_input_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/send_msg_button"
android:background="#FFFFFF"
android:hint="Type a message...Type a message...Type a message...Type a message...Type a message...Type a message...
Type a message...Type a..."
android:inputType="textMultiLine"
android:maxLines="5"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:shadowColor="#000000"
android:shadowRadius="3"
android:shadowDx="3"
android:shadowDy="3"/>
</RelativeLayout>
</RelativeLayout>

cannot see edittext in relativelayout (offscreen)

I have the following relative layout that has a listview with an EditText underneath. I can't see the edittext as the list takes up the whole screen.
how can i show both the listview and the edittext on the screen at the same time without scrolling?
i've tried numerous layout params
thanks
<?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"
>
<TextView
android:id="#+id/textviewassessments"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="#color/blue_alpha_background"
android:textColor="#FFFFFF"
android:text="Assessments" />
<ListView
android:id="#+id/assessmentslist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#8fff"
android:cacheColorHint="#0000"
android:padding="5dp"
android:divider="#FFCC00"
android:dividerHeight="4px"
android:layout_below="#id/textviewassessments" >
</ListView>
<EditText
android:id="#+id/editTextassessments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="1"
android:lines="7"
android:inputType="textMultiLine"
android:hint="Please type any comments..."
android:layout_below="#id/assessmentslist" >
</EditText>
</RelativeLayout>
If you want to use RelativLayout then you should put one elment to the bottom and place the other above. Sample (not tested)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/editTextassessments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="1"
android:lines="7"
android:inputType="textMultiLine"
android:hint="Please type any comments..."
android:layout_alignParentBottom="true" /> <!-- this will put the element on the bottom of the screen -->
<TextView
android:id="#+id/textviewassessments"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="#color/blue_alpha_background"
android:textColor="#FFFFFF"
android:text="Assessments"
android:layout_alignParentTop="true"
/> <!-- this will align the element to the head -->
<ListView
android:id="#+id/assessmentslist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:background="#8fff"
android:cacheColorHint="#0000"
android:padding="5dp"
android:divider="#FFCC00"
android:dividerHeight="4px"
android:layout_below="#id/textviewassessments"
android:layout_above="#id/editTextassessments"
/> <!-- this will put the the list between the both elements and stretch its size due match parent -->
</RelativeLayout>
Change your EditText and align it to the bottom. Right now, you are telling it to be below the list so if the list takes up the full height then there is no room for it.
<EditText
android:id="#+id/editTextassessments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="1"
android:lines="7"
android:inputType="textMultiLine"
android:hint="Please type any comments..."
android:layout_alignParentBottom="true" > //here
</EditText>
If you want it to be below the list no matter what (even if the list doesn't fill the whole screen) then you may want to use addFooterView()
Try:
<EditText
android:id="#+id/editTextassessments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="1"
android:lines="7"
android:inputType="textMultiLine"
android:hint="Please type any comments..."
android:gravity="bottom"
android:layout_alignParentBottom="true" >
</EditText>

Categories

Resources