Select All Text In a fragment - android

I have searched a lot, but I still cannot find any way to do this. I have a Fragment , which comprises of a LinearLayout. the LinearLayout has some TextView's and some nested LinearLayouts. Even the nested LinearLayouts have nothing other than TextViews. There is no other kind of View except for these two. I have made the TextViews selectable, but by this, at one time, I can only select the text of one TextView. I want to enable the user to select all text in all TextViews (in HTML, Web page style) and preferable be able to copy it to clipboard with the presented formatting. Is this possible in Android?
Edit:
I had originally considered making it a single TextView, and adding all the content inside it. However, I want to direct different parts of the text to different places (URL, phone, email, map), and while I know that this should have been possible using android:autolink="all', it didn't work as I expected and I had to separate the text into different parts in order to be able to do it. Any way this is achievable?

Create only one text view and set the textview with HTML tags.
Simple Example,
textView. setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Or
Add the string in resource with HTML tags and then set the text in code
textView. setText(Html.fromHtml(yourHtmlText);
Note : most of the tag will be supported , not all. Example you can't set font size but can set it as small, big ..

Related

textview doesn't wraps correctly?

I've two textviews aligned horizontally. when the second TextView becomes longer it wraps to the next line incorrectly. I want it to start the text from the beginning of the layout instead of just below the TextView.
I've tried flow layout but it wrap all the text to the bottom rather than wrapping just the additional text.
What I want :
The reason I want two TextView is because I'm working on Drag and Drop quiz, so when the user drags the answer to the textview it will change it's content "setText(answer)" to be the answer.
Thank you for helping
Drag and drop image
I don't think that this is possible. You can always use string with arguments to achieve that.
e.g.
<string name="test_string">%1$s %2$s</string>
and then
getString(R.string.test_string, "text view one text", "text view two text")
I'm not sure this is possible. It sounds like an awkward way of going about something quite simple.
My solution would be to have 1 TextView, and join the two strings together that would otherwise be in separate TextViews.
Instead of two textViews, take two string variables and work on them. in the end, just concatenate two strings and display it in the textView.
In order to give it look and feel of two different textViews, you can either use html format, or spannable text.
We might be able to help understand your problem better if you can explain the actual scenario, and why two textViews are necessary.

How to make RecyclerView with multiple ViewHolders so that one ViewHolder is also controlling another ViewHolders content

I'm trying to implement horizontal scrolling view and managed to actually implement it using this tutorial. Horizontal RecyclerView tutorial
It has it's problems on focusing but at least it works.
Depending use case i have about 2-8 different images to view.
Now my problem comes that my layout is looking like this.
Current layout There is also other fields which isn't included in image.
Now images comes to image field and text would come to text field.
I would like to make those so that when image is moved also text will move at text field but not another way around. When trying to move from the text field it doesn't do anything.
in that tutorial both text field and image field are in same layout but i have separated those and also have that third field which isn't part of the RecyclerView. And adding more to this mess i also have button and when pressing it will change to next image on image field at below layouts.
So what would be good approach to make this to work??
http://smstuebe.de/2016/06/12/mvvmcross-recycler-templates/
You must create an interface to return proper layout for each of your element. You must define all the type of layout in the template selector

how to add search result on top of other views

I have an EditText in my layout which is used to get the search query from the user. I want to show a LinearLayout bellow it when user enters some characters and fill it with the results (This layout should appear after entering at least N characters). But I don't know how to show this layout?
I thought of putting the whole layout shown in the activity inside a FrameLayout and add the view when required, but there will be two problems:
The view will be added on the top left of the screen.
If I want to move it with adding some padding to it, all the area will correspond to the click event.
To explain what I want more, please take a look at this:
I hope this link will help you, you need to use AutoCompleteTextVIew
http://www.javatpoint.com/android-autocompletetextview-example
https://www.codeofaninja.com/2013/12/android-autocompletetextview-custom-arrayadapter-sqlite.html
These is two approaches for your case.
Use AutoCompleteTextView
Use android-popupwindow.
The former is easier and more acceptable, however if your want to customize the layout of the resulting search, for example arranging them in a gird view, you may what to use the latter option.
Although, AutoCompleteTextView internally uses the latter option.

Android different media in one view

Ok I do have a question regarding how I would implement this function:
I am creating an application, and in one activity, I want to display several information in the upper half of the screen. Now if I want to display an image, I chose ImageView, if I want to display text, I use TextView, and so on. The user choses what do display in the activity that comes before the display-activity.
Now my question: What kind of View do I chose for this? I was thinking about a WebView, to display images or text. But there is also a chance that I have to display a player for a .wav-file. Does WebView also provide this function? My Problem is that I cannot just say that I chose an ImageView, because it displays no text, and so on. I need a container that can display everything.
Or is there a possibility to overlap like 3 different containers, and activate only the one that I need?
You can have all 3 views in the layout and use Visibility.GONE to hide the ones you don't want. Or you can dynamically add a insert a view at runtime. A simple way to do this second solution would be to put a placeholder view there in your XML layout, and at runtime remove this view and dynamically insert your desired view in it's place.

Layout Form with Long Labels

I am having some difficulty with an Android layout problem. I am trying to make a form for users to fill out. This form is defined programmatically (from a server-provided configuration over which I have no control) and thus I must implement it programmatically. The form has several different field types, but for simplicity we can assume they are all simple text fields (EditText).
I currently have the form implemented as a vertical LinearLayout. For each field I have a horizontal LinearLayout that contains a TextView for a field label and an EditText for the user to enter a value for the field. I have the EditText set to fill the width using LinearLayout.LayoutParams(FILL_PARENT, WRAP_CONTENT).
This works well when the TextView label is short, but when it is long it causes the EditText to be very small and makes it hard for the user to enter a value. Ideally I would like the EditText to be at least half the width of the screen with the TextView label wrapping if necessary. I've tried a TableLayout with TableRows but I still had difficulty. I would also rather not force a grid and thus waste the space on the lines with short labels (assuming the other requirements are met I'm flexible on this). I would have tried something like a FlowLayout to force the EditText to wrap onto the next line but it's not supported on Android.
Any suggestions for how I can make this work better? XML-based solutions will be accepted assuming I can port them to a programmatic approach. I would also like to make this as flexible with respect to screen size and orientation as possible, so this means avoiding hard-coding any widths.
Thanks in advance.
Try playing around with layout weights. You should be able to tell your two items to each take up half the screen, for example, by setting the width=0 and layout_weight=1 for both.

Categories

Resources