Java Question Vertical Scrolling EditText

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I'm having a problem getting an Edit Text created by code (No XML) to work how I expected. It is in a Relative layout and width/height are set to wrap content. My First Requirement was wrapping text which I got with:

B4X:
NewView.setHorizontallyScrolling(false);
NewView.setHorizontalScrollBarEnabled(false);

Once the EditView expands to parent bounds or a MaxEMS it wraps which is great.

Now, I at first wanted to be able to choose MaxLines and have it start out at one line to save space and expand when needed to a max of say 5 lines visible then the rest scrolls internally. This doesn't work at all and the EditText just keeps expanding. Then I tried using SetLines which partially worked by making it 5 lines to start, but still kept expanding.

So, I figured maybe it was that scolling vertical wasn't enabled, but setVerticalScrollBarEnabled(true) caused a Force Close. I found a few more articles that mentioned setting a scroller, so I added setScroller(new Scroller(ba.context)) and now it didn't force close, but still expanded without scrolling.

I've also tried setScrollContainer(true), but I read mixed input on whether it even applies to EditTexts. I even tried setMovementMethod(new ScrollingMovementMethod()), combinations of the above, and all of the above. Nothing stops it from expanding.

I think if I give it a static size it may scroll, but I need to get the proper statements required for this because when I do that now it Force Closes when it hits the bounds with text. Static sizes kind of defeats the purpose of what I'm designing too. I'm a little disappointed MaxLines does nothing, but in reading further it may be more for Singleline wrapping more like a label.

Does anyone know what is needed to make an EditText scroll vertically by code? Standard B4A EditText do it, but they have static sizes. If I can at least get the right combination to scroll at all maybe I can just measure line height or something if it won't stop expanding on its own.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Well, I thought I'd be slick since my views also use B4A views within the library and just replace all my calls with:

B4X:
b4aTextbox.setSingleLine(false);
b4aTextbox.setWrap(true);

But, it still expands vertically. So, it looks like I will have to figure this out another way. Android really didn't code their Lines and MaxLines correctly.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…