3

I am trying to create a paragraph of text using TextView and need to insert EditText in between text like fill in the blanks. Is it possible to build custom view like that ? As I am new in this forum I could post any image. It should look somewhat like below:

World is a common name for the whole of human [EDIT TEXT], specifically human experience, history, or the human condition in general, worldwide, i.e. anywhere on Earth.[2]

In a [EDIT TEXT] context it may refer to: (1) the whole of the physical Universe, or (2) an ontological world (see world disclosure). In a [EDIT TEXT] context, world usually refers to the material or the profane sphere, as opposed to the celestial, spiritual, transcendent or sacred. The "end of the world" refers to scenarios of the final end of human history, often in religious contexts.


ok. Now I can post images :-) In the image below, red colored cells are edit texts. Other colored texts are textviews (sorry too much bright colors). Now, if I use leftOf/rightOf methods in RelativeLayout it will look like the second image. Am I thinking in the wrong direction ?

image

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Civitas
  • 75
  • 9
  • You need to use Relative Layout with combination of TextView and EditText. – kosa May 02 '12 at 21:32
  • problem is how will i know where to place my edittext in the RelativeLayout. Text is dynamic. I don't want to calculate x,y coordinate for this. That would be really dirty. Is there any better way ? – Civitas May 02 '12 at 21:42
  • In Relative layout usually you say ontop, beside etc., you don;t need to hard code x,y layout. It is easy and should work. Try one example. I am not at my personal computer now to get you one example. – kosa May 02 '12 at 21:46
  • 1
    http://stackoverflow.com/questions/4474237/how-can-i-do-something-like-a-flowlayout-in-android –  May 02 '12 at 22:27

2 Answers2

2

It doesn't seem like there is an easy way to do this without making your own layout manager. See this post for a line-breaking widget layout implementation. You can also achieve something similar by using Romain Guy's FlowLayout implementation.

I've never used either of these implementations before to achieve the "fill-in-the-blank" effect you described, but it seems to me that you would need to add the TextView and EditText objects via the layout's addView method. You might have to experiment a little to get it working correctly, but I think this should help you get on the right track.

Community
  • 1
  • 1
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
2

i think the best way would be to create your own editText view . however, this is probably a very hard thing to do.

if you are short in time , you can use HTML and use a webView to show the content . i'm pretty sure that in html this task is much easier , as it's already implemented in many places.


EDIT:

another solution is to use FlowTextView library . it extends from RelativeLayout, but acts as a textView. i didn't test it but only ran their sample (via a cool app called DevAppDirect)

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • problem is i need to get value of those edit boxes in java. I don't think I can do it with the web view. – Civitas May 02 '12 at 23:50
  • of course you can . look at this demo: http://developer.android.com/resources/articles/using-webviews.html . it will show you how you can communicate between android<=>javascript . the new problems is handling html in a good enough way . i'm not an html expert , so i can't be sure how easy it is . i do know that creating customized views can be quite challenging . – android developer May 03 '12 at 06:59
  • thanks ..i will definitely try this ..I plan to start this work after few weeks. I posted the question early to get suggestions/solutions beforehand. I will let you know if I am successful with this. – Civitas May 03 '12 at 17:55
  • finally i tried with webview and javascripts. It worked. I could pass data from Webview to JS and vice versa. Thanks for your help. – Civitas Jun 21 '12 at 14:55
  • cool . sadly it probably doesn't look quite native , and you probably need to test it on multiple resolutions , right? – android developer Jun 21 '12 at 15:34
  • yes .. I have already started facing issues .. I have posted a separate question on how to store images for different resolutions .. moreover, while initial loading of webview I want to populate few edit fields ... I am using JavaScriptInterface to communicate between java code and javascript .. somehow, data is not reaching javascript during initial load .. after page is loaded if i try to populate those fields by clicking a android button it works .. i tried to send the data from onResume of Fragment ..but, it does not work .. i am planning to post another question on this separately – Civitas Jun 21 '12 at 23:11
  • nice . if you wish , maybe this link could help about preparing the webpage for android : http://developer.android.com/guide/webapps/index.html – android developer Jun 22 '12 at 14:39
  • i've added another possible solution to this problem. – android developer Jun 28 '13 at 07:13