0

I have a sentence, user has to put his data into sentence (one word).

I tried to use for it LinearLayout with TextView (beginning of the sentence), EditText with ems=5(here user should put his data), then TextView(end of the sentence) (See the code below). But in this realization it doesn't look appropriate, when we use long sentence and it moves part of it to the next line.

On emulator it looks like:

|Blablabla ________ blablabla| | blabla. | 

It puts the end of the sentence under the second TextView. But I need that the second line starts from the beginning of new line, like:

|Blablabla ________ blablabla| |blabla. | 

I tried to use the solution from Git-Hub: flow-text but got that kind of result: enter image description here

How can I solve this problem? Thanks for watching this post!

XML:

<LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="4dp" android:layout_marginTop="4dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="15dp" android:paddingRight="5dp" android:textSize="20sp" android:text="@string/firstPart_1" android:id="@+id/textView1"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/name" android:textSize="20sp" android:inputType="textCapSentences" android:paddingTop="2dp" android:paddingBottom="6dp" android:ems="7"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="15dp" android:paddingRight="5dp" android:textSize="20sp" android:text="@string/firstPart_2" android:id="@+id/textView2"/> </LinearLayout> 

XML (flow-text):

 <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" android:orientation="vertical" 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"> <ScrollView android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" > <uk.co.deanwild.flowtextview.FlowTextView android:id="@+id/ftv" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="5dp" android:textSize="20sp" android:text="блабла" android:id="@+id/textView1"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/name" android:textSize="20sp" android:inputType="textCapSentences" android:ems="5"/> </LinearLayout> </uk.co.deanwild.flowtextview.FlowTextView> </ScrollView> 
2
  • Either the textviews will wrap or be truncated for long strings if you force them to a single line.... I can't see a way around that Commented Jan 9, 2016 at 19:20
  • Why you are not having the complete textview and on clicking on the textview opening a dialog or popup to enter the text? Commented Jan 9, 2016 at 19:25

2 Answers 2

2

I think you should use the linear layout (horizontal) for a single line.

 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="fill in the blanks:" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Your name is: "/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5"/> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello Brother, how are you" /> </LinearLayout> 

It is working as you want. :)

Sign up to request clarification or add additional context in comments.

3 Comments

This time I have provided the complete code... which worked as you want to do.
Sorry, but it complitly doesn't work how I want. I need to put TextView in one line with EditText, after it, if TextView too long moves it in the beginning of the second line.
you need to put only that number of words in the horizontal linear layout(we are using it for only a single line which is having edit text )such that it doesn't jump to the second line. Remaining words you can put after the horizontal linear layout.
0

Since your text is going to be of rich format as shown in the picture, you can consider using a WebView.

In this case, you can arrange your elements using HTML and use rich texts using CSS styling.

Also you can use WebView mechanisms provided for communication between Java side and JavaScript side, in order to make a bridge from that text box to your Java logics. (Example)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.