TheShinyGoombah
TheShinyGoombah

Reputation: 53

How to make EditText Scroll?

I'm having a trouble finding exactly what I'm looking for on the Internet for what I want to do. I have an EditText, and sometimes whatever the user inputs to the EditText will exceed the width of the field. I already have it setup so that it has HorizontallyScrolling so it doesn't push anything else out of place, but now I want to have my text scroll from left to right, and when it reaches the end of the text, it repeats.

If anyone has a solution to this I would be super excited to get that working. If anyone wants more clarification on what I want, I'd be happy to give it. Thanks all!

Upvotes: 1

Views: 145

Answers (1)

Petro
Petro

Reputation: 3662

Something like:

edittext.setScroller(new Scroller(myContext)); 
edittext.setMaxLines(1); 
edittext.setVerticalScrollBarEnabled(true); 
edittext.setMovementMethod(new ScrollingMovementMethod()); 

Update:

private final void focusOnView(){
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                your_scrollview.scrollTo(0, your_EditBox.getBottom());
            }
        });
    }

Or for grabbing the keypress's:

public boolean onKey(View v, int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
         /* This is a sample for handling the Enter button */
      edittext.requestFocus();
      return true;
    }
    return false;
}

I looked at these threads:

Is there a way to programmatically scroll a scroll view to a specific edit text?

Catch keypress with android

Upvotes: 1

Related Questions