0

I implemented a customized keyboard as a popup window as below.

LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
keyboardView = layoutInflater.inflate(R.layout.keyboard_guess, null);
final PopupWindow popupWindow = new PopupWindow(
                    keyboardView,
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    true);

// init keyboard keys
setKeyBoardKeys();

popupWindow.showAtLocation(keyboardView, Gravity.BOTTOM, 0, 0);

The custom keyboard pops up when I select an element in a row of the list view.

Everything works fine. But when I select an element at the bottom of the list the popup keyboard hides the selected row. How can I prevent selected row not be hidden by the popup keyboard by moving the list up.

madu
  • 557
  • 6
  • 14

1 Answers1

0

Trick is in resizing the list view. I did it by toggling the height of the list with the view under it (footerView). And by smooth scrolling to the item. Scrolling won't work unless you dispatch the event to the UI thread via post(). (For more on post() check out this).

Below is the solution I had for the above issue.

        // re size the list view (push up) to provide space for the keyboard
        mListView.post( new Runnable() {
            @Override
            public void run() {
                LinearLayout.LayoutParams lParams = (LinearLayout.LayoutParams) mListView.getLayoutParams();
                View footerView = findViewById(best_guess_list_footer);
                LinearLayout.LayoutParams fParams = (LinearLayout.LayoutParams) footerView.getLayoutParams();


                listHeightWeight = lParams.weight;
                mListView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 0, fParams.weight));
                mListView.requestLayout();
                mItemAdapter.notifyDataSetChanged();
                mListView.smoothScrollToPosition(position);
            }
        });

        popupWindow.showAtLocation(keyboardView, Gravity.BOTTOM, -100, -100);

Hope this will help someone.

Community
  • 1
  • 1
madu
  • 557
  • 6
  • 14