Android EditText Control Scrollbar - android

<EditText
android:id="#+id/textbox"
android:singleLine="true"
android:scrollbars="horizontal"
android:scrollHorizontally="true" />
((EditText)findViewById(R.id.display)).setKeyListener(null);
the EditText serves as some kind of log box, text is appended to it at some events.
I need the EditText to be scrolled to the right at all times, I mean the scrollbar should be positioned to the maximum right and so the most recent text is visible.
I cant seem to get it done, not sure how to read the current position of the scrollbar and adjust it accordingly.
I've tried playing with EditText.setScrollX() though even setScrollX(10000) didnt have any effect.

try with
editText.setSelection(editText.getText().length()-1);

Related

Android: Spaces not going to new line at the end of EditText line

I have a multiline EditText.
Whenever the input text is reaching its maximum width, the line breaks and the text is moving to the next line.
However, it isn't working well with spaces. When there is an input like "blabla" and then lots of spaces, the line not breaks and the text is being pushed to the left until it "goes out" of the EditText.
How can I treat the spaces as "regular" characters for it to work?
thanks!
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:inputType="textMultiLine|textCapSentences|textNoSuggestions"/>
If you don't like the horizonal scrolling on trailing spaces, I think you will have to give up android:gravity="center". That is causing the scrolling. I tried adding android:scrollHorizontally="false", but it had no effect. I couldn't find a way to stop the scrolling when center gravity is specified.

Why doesn't nextFocusDown work with TalkBack navigation?

I have four TextViews, and I'm trying to control the order that they get focus when a user navigates using TalkBack and touch gestures.
TextView android:text="foo" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="#+id/id_foo" android:nextFocusDown="#+id/id_baz"/>
TextView android:text="bar" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="#+id/id_bar" android:nextFocusDown="#+id/id_qux"/>
TextView android:text="baz" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="#id/id_baz" android:nextFocusDown="#id/id_bar"/>
TextView android:text="qux" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="#id/id_qux" android:nextFocusDown="#id/id_foo"/>
When a user turns on TalkBack, touches "foo", and then swipes down to navigate between the TextViews, I want the order to go foo->baz->bar->qux. But, the order I try to set up using nextFocusDown seems to have no effect, and instead focus order always just follows the positions of the TextViews on the screen. I've tried every possible combination of clickable, focusable, and focusableInTouchMode. I've tried calling setNextFocusDownId on the views in code. I've tried setting android:imeOptions="actionNext" on the TextViews. Nothing seems to work. What am I missing?
Try to use View.setAccessibilityTraversalAfter(int) and View.setAccessibilityTraversalBefore(int) to configure TalkBack navigation. Please note that TalkBack has only two directions:
forward (swipe to the right or down)
back (swipe to the left or up).
Example:
findView(R.id.bar).setAccessibilityTraversalBefore(R.id.quix);
NextFocusDown doesn't refer to TalkBack gestures. It refers to track-ball and keyboard arrow key navigation. TalkBack exploration gestures are limited to swiping down/right for next focus, and swiping up/left for previous focus. And of course, drag to explore.

Horizontol scrollbar in android text view

I have a expandable list view consisting of varied sized textviews. The TextView size depends upon the contents in it. Now there are certain text which exceeds the screen width and the user is not able to view it.
I have tried HorizontolScrollView inside a ScrollView. It performs the scrolling but as my UI is a bit complex, it doesnot renders the other widgets in the view (like checkbox) properly.
Please suggest some good ideas to do the manual text scrolling.
Marquee is not a good suggestion. :)
Thanks in advance
Nested scroll view is a big 'no no' in android as there is no good way to determine which scroll has focus.
My solution would be to make an non-editable EditText. I would do something like this.
<EditText android:scrollHorizontally="true"
android:editable="false"
android:enabled="false"
android:layout_width="match_parent"
android:id="#+id/editText1"
android:layout_height="wrap_content" >
</EditText>
TextView seems to have a android:scrollHorizontally property as well but I have had no luck getting it to function.

Soft Input pans view but not enough to show full editText

I have a somewhat complicated layout, but at the very bottom is a huge EditText. When I click on it to get the keyboard to open, everything slides up just enough to show exactly where the user is typing (as the user begins typing only 1 line is visible, if the user goes to multiple lines then it pans a little more to show 2 lines, etc). I would like everything to pan so that the whole EditText (all the blank space) is visible.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:orientation="vertical">
<EditText
android:id="#+id/CommentBox"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:textSize="16sp"
android:layout_marginLeft="6dp"
android:layout_marginTop="4dp"
android:background="#color/transparent"
android:textColor="#color/gray"
android:gravity="top"
android:inputType="textMultiLine|textCapSentences|textShortMessage|textAutoCorrect|textNoSuggestions">
</EditText>
</LinearLayout>
Been struggling with this for a couple days now, would appreciate any suggestions.
Best way to illustrate is with 3 images
This is what the entire screen looks like
This is what the behavior is right now
This is the desired behavior
Hopefully the images illustrate my question. I need to figure out how to make this happen. The only way I have been able to force view to pan to the right place is by setting, android:gravity to bottom , in which case text is written at the bottom. This however, is clearly a very weird user experience. I need text to be like in a normal text box.
Was able to hack together a solution that mimics what I was looking for.
Put the layout inside a scrollView, set the parameter to adjustResize instead of adjustPan. And on click in the editText did
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getBottom());
}
} , 250);
Would love to find a non-hacky way to do this, but this is all I've got.

Programmatically scrolling an EditText

I'm writing a simple caesar-encryption-activity. Two EditTexts on screen, one clear-text, one crypted. Here's an example for the crypted EditText - the cleartext one is similar.
<EditText
android:layout_below="#id/Caesar_Label_CryptText"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/Caesar_Text_CryptText"
android:hint="Enter crypted text"
android:maxLines="2"
android:lines="2"
android:minLines="2"
android:inputType="text|textMultiLine|textVisiblePassword"
android:scrollbars="vertical"
android:gravity="top" />
Now when entering cleartext I have an TextChangedListener running that programatically crypts and fills that crypto-EditText. So far, so good.
When the cleartext entered gets really long, the cleartext-EditText scrolls with my imput, but the crypto-EditText stays at the top of the text. I'd really like the crypto-EditText to scroll so that it always shows the bottom line of its content.
How can that be done, preferably from the onTextChanged()-Method of the TextWatcher?
Ok, found it. It was the cursor (called Selection on EditText and TextViews).
This is how I got it to work:
ivClear // assigned the EditText that has the input
ivCrypt // assigned the target EditText, that I want to scroll
aText // the input from ivClear, crypted
Then use:
ivCrypt.setText(aText); // assign the Text
ivCrypt.setSelection(ivClear.getSelectionStart()); // scroll
Phew, finally :) Always underestimated the power of the Spannable ;)
The base class android.view.View has methods getScrollX(), getScrollY() and scrollTo() that may be helpful, though I haven't tried it.
http://developer.android.com/reference/android/view/View.html#scrollTo(int, int)

Categories

Resources