I have a android.widget.EditText (in multi line read only mode) in which I display some informations (the left half):
From time to time additional informations are added to the end of this android.widget.EditText and then I would like to scroll to the end of the the field (perhaps only scrolling to the end if already positions at the end which I think is even more user friendly).
Surprisingly I was unable to find any information on cursor and scroll movement in android.widget.EditText.
I found this posting but i don't have a ScrollView and I wonder why would I want one as a android.widget.EditText can handle it own scolling.
Any ideas or insights? What did I miss?
If scrolling to the end is all you want then the following will do:
this.Printout.setText ("");
this.Printout.append (Service.Get_FP10_Printout ());
The trick here: android.widget.EditText.append will scroll to the end of the field for you. So I delete the text and then append what I want to display.
If you need any other scrolling then you need to envelop the android.widget.TextView with an android.widget.ScollView (as lumis suggested) and use the trick from Patrick.
You know, Casio FX602P was my very first programmable computer!
I am not sure if editView can be made to scroll on its own, but if you envelop a textView with a scrollView and disable the scroll bars you should get what you need.
One other possibility came to my mind; if you use a List instead that would allow not just to scroll but to select the line of code which one wants to edit in the display on the right...
To accomplish this you must wrap the EditText in a ScrollView and control it through it's parent. It was previously possible to simply use EditText.append to accomplish this as indicated by one of the answers append here. However google has made all standard EditText's AppCompat now which has changed the behavior of the append function, it no longer scrolls to the end.
I found out the hard way as my app's functionality changed after a compile with the newer API.
Related
I was wondering how to make a text editor toolbar for an android app using Kotlin.
I've already implemented the view as you can see here. But I can't find a way to make it work propperly. I've tried to use Spannable String and Typeface but I think that they are not what I am looking for.
When using spannable, I need to put some string. But I can't put a string because there may be no text yet.
Maybe using the textchange listener of the EditText would work? I've tried it too but it doesn't seem to fit into my logic.
This is what I was thinking about: A listener for every button. Whenever a button is pressed, add that style to the future text that will come. To specify the start and the end of the text, maybe I could take the current position of the cursor to specify the start and the position of the cursor whenever the button is "unpressed" to specify the end. But I can't find something that fits my logic.
Maybe you could give me some ideas, another logic...Which is the proper way to do it?
Thank you very much :)
In my android application, I am displaying a long string into multiple pages. I achieve this by breaking the long string into a string array where every array element holds the number of characters which can fit on one screen (without scrolling). Also by using a previous/next button at the bottom of my activity I change the content of my textview to switch between pages(array elements).
Where I am stuck is in finding out how many characters will show on one page/screen. Remember I don’t want user to scroll. I use the paint.breaktext with screenwidth as the parameter and find out how many characters go in one line and then multiply it by number of lines on one screen to get the number of characters in a page. Android’s text wrapping at the end of each line is what gets my calculation of finding characters in a page, wrong. I am trying to put my own logic to accommodate for text wrapping but that is not working.
So my question is:
Is there any way I can find out that how many characters will show in one screen?
Or what can also help me is if I find out what logic is followed by android for wrapping the text for newline. Because if I know that, then I can readjust my number of characters on a page accordingly.
Or other option could be to disable text wrapping (not sure if possible). Because then I can use my own logic to wrap the text rather than trying to figure out Android’s text wrapping logic and adjusting my character-on-a-page accordingly.
Any help is much apreciated.
I dread designing UI for Android apps, and I have been searching and trying every possible combination of things to get this the way I want it, but I just cannot seem to get it right.
I want to have a simple Android app that has a text field and a send button next to each other on the bottom of the screen (I already have this correct), and I also want a functional chat area filling the rest of the screen above.
It obviously needs to be scrollable, and I would like to be able to add a new line to the bottom of the chat by doing something like chatBox.add(username, text).
This is the type of view I am looking for:
<bob> my name is bob
<bill> hi bob, my name is bill!
<bob> we are having an awesome conversation, bill
<bill> both of our names start with a b
<bob> how right you are
I had made such app. For chat window I used listView. ListView has stackFromBottom mode. So the last added messages will be on the bottom of ListView. Also I created custom Adapter extending ArrayAdapter, so it is easy to add new messages.
Here is a nice example, how to use listView with adapter and add new items.
Leonisdos is right, you shoud use listView. Do you know the app Irssi-ConnectBot ? I think you should have a look in its source code to have many good examples.
Here the code.google project of Irssi-connectbot (and the github)
Wrap a TextView in a ScrollView. Use append() on the TextView and fullScroll(View.FOCUS_DOWN) on the ScrollView when you append new chat entries.
For longer chats, Leonidos' ListView approach is more efficient, but I thought I'd mention this one.
i have an AutoCompleteTextView widget on the view. if it has input focus and I'm trying to change the text in there with:
txtField1.setText("test");
I'm getting suggestions list appears on the screen. How do I hide it? is it possible to update the text not showing suggestions?
I'll leave this here, in case someone needs it in the future, like I did.
yourAutoCompleteTextView.dismissDropDown();
will make the list with suggestions disappear from the screen.
I suggest some methods
1)If you want to make "test" like hint of autocomplete textView then do like this,
txtField1.setHint("test");
2)If you need to fill up the text view with "test" and also need to prevent the suggestion increase the threshold level for auto complete textview ,
txtField1.setThreshold(5);
if you use threshold it will show suggestion after 5 character (according to the code posted in above line). If you need try to set different word and also try to avoid suggestion , change the threshold dynamically based on length of string.
I'm trying to make iPhone-style EditText element on android.
The one that will have an additional clear button appear on the right after text input.
Adding a new button is not a problem, but I'm a bit stuck with another thing.
A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?
I want EditText width to be N pixels, and editable area to be N-M pixels.
EditText.setWidth changes width for whole edit box.
EditText.setEllipsize should be the proper solution, but docs are empty, and as I see it truncates text based on some String value.
Applying a LengthFilter cut's the input length to number of characters.
Thanks in advance.
I suspect that android:drawableRight will save you a lot of pain.
Seems I've found a solution.
EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area
Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/
This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area.
This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.
Alternatively you can use the compound drawables, but you would need to implement something like this
Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.