Arjun saini
Arjun saini

Reputation: 4182

how to disable or hide the right and left arrow from keyboard with ViewPager android

I am trying to disable left and right on the keyboard with this code but viewPager on the press of left and right button change the state of the pager.

edComment.setOnEditorActionListener(
    new EditText.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

        if (actionId == EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS
                || actionId == EditorInfo.IME_FLAG_NAVIGATE_NEXT
                || actionId == EditorInfo.IME_ACTION_PREVIOUS
                || actionId == EditorInfo.IME_ACTION_NEXT
                ) {


            return false;


        }
        // Return true if you have consumed the action, else false.
        return false;
    }
});

enter image description here

Upvotes: 1

Views: 717

Answers (3)

Catalin
Catalin

Reputation: 159

You can extend the ViewPager and override the arrowScroll method like this:

public class Wizard extends ViewPager {
    @Override
    public boolean arrowScroll(int direction) {
        // Never allow pressing keyboard arrows to switch between pages
        return false;
    }
}

Upvotes: 7

Arjun saini
Arjun saini

Reputation: 4182

According to @Gabe Sechan button are not hide or disable so I am doing like that

  @Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    Log.i("your tag", "Keycode: " + keyCode);
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
           Log.e("Click","left");

           /* for (int n = 0; n < count; n++) {

                setCurrentPage(arrayListView.get(n + 1));
            }*/


            pager.setCurrentItem(getItem(+1), true);
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            Log.e("Click","right");


            pager.setCurrentItem(getItem(-1), true);



            return true;
        case KeyEvent.KEYCODE_DPAD_UP:
            Log.e("Click","up");
            return true;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            Log.e("Click","Down");
            return true;
        default:
            return super.onKeyUp(keyCode, event);
    }
}

Upvotes: 0

Gabe Sechan
Gabe Sechan

Reputation: 93678

The keyboard app can show whatever keys it wants. There is no way to force it not to show certain buttons, and even if there was another keyboard wouldn't follow the same rules.

Upvotes: 2

Related Questions