How to get height of keyboard when activity created in android
<p>I want to auto display a listview with same height of keyboard of device when user goes to that particular activity. For this, I am calling three methods that are, showKeyboard(), getKeyboardHeight() and then hideKeyboard() and then giving height to that listview and showing that listview. But the problem is once I call showKeyboard(), calculate height and then hideKeyboard(), the keyboard doesn't hide and remains visible. Also I'm getting height as 0. I cannot display that listView. Is there any another process to get height of keyboard or any correction in below code ? See the code below :</p>

<p><strong>showKeyboard() method -</strong></p>

<pre><code>private void showKeyboard() {
             InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
             keyboard.showSoftInput(editChatBox, 0);
        }
</code></pre>

<p><strong>getKeyboardHeight() method -</strong></p>

<pre><code>public int getKeyboardHeight() {
          final View rootview = this.getWindow().getDecorView();
           linearChatLayout.getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    public void onGlobalLayout() {
                        Rect r = new Rect();
                        rootview.getWindowVisibleDisplayFrame(r);
                        int screenHeight = rootview.getRootView().getHeight();
                        int newHeight = screenHeight - (r.bottom - r.top);
                        if (newHeight &gt; heightOfKeyboard) {
                            heightOfKeyboard = screenHeight
                                    - (r.bottom - r.top);
                            // heightOfKeyboard = heightDiff;
                        }

                        Log.d("Keyboard Size", "Size: " + heightOfKeyboard);
                    }
                });
        return heightOfKeyboard;
    }
</code></pre>

<p><strong>hideKeyboard() method -</strong></p>

<pre><code>private void hidekeyBoard() {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editChatBox.getWindowToken(), 0);
}
</code></pre>

<p><strong>Inside onCreate() method -</strong> </p>

<pre><code>@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chat_new_layout);

   ArrayAdapter&lt;String&gt; chatQueAdapter = new ArrayAdapter&lt;&gt;(this,
            R.layout.chat_que_row, R.id.textChatQue, queArrays);
    myListView.setAdapter(chatQueAdapter);

        showKeyboard();
        heightOfKeyboard = getKeyboardHeight();
        hidekeyBoard();
        myListView.getLayoutParams().height = heightOfKeyboard;
        myListView.setVisibility(View.VISIBLE);
    }
</code></pre>