3

I have a problem, I have a ListView and an EditText designed like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ShoutboxTab" >

    <ListView
        android:id="@+id/shoutbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/shoutbox_field"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="14dp"
        android:layout_marginRight="20dp" >
    </ListView>

    <Button
        android:id="@+id/shoutbox_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/shoutbox_field"
        android:text="Shout" />

    <EditText
        android:id="@+id/shoutbox_field"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/shoutbox_button"
        android:layout_alignLeft="@+id/shoutbox"
        android:ems="10" >

        <requestFocus />
    </EditText>

</RelativeLayout>

So the EditText is under the ListView. When I have items added to the ListView and I click the EditText to type, the keyboard overlaps the bottom part of the ListView. I want to make sure the bottom part of the ListView goes up with the keyboard. Is this possible? Thanks

Black Magic
  • 2,706
  • 5
  • 35
  • 58

4 Answers4

3

use <activity android:windowSoftInputMode="adjustResize"> in your menifest. second add android:transcriptMode="alwaysScroll" property in your <ListView />

Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57
1

Are you using <activity android:windowSoftInputMode="adjustResize" ... > in your Manifest? http://developer.android.com/training/keyboard-input/visibility.html

adam0101
  • 29,096
  • 21
  • 96
  • 174
Peter
  • 1,769
  • 1
  • 14
  • 18
  • I put it in, didn't help. Could that have anything to do with the fact that I am using fragments for a tab view? – Black Magic Dec 31 '13 at 17:58
  • adjustPan should do it according to this post.http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft gives a full list of available options. – Peter Dec 31 '13 at 18:22
0

I fixed it like this:

V.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                int heightDiff = V.getRootView().getHeight() - V.getHeight();
                if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                    shoutbox.setSelection(adapter.getCount() - 1);
                }
             }
        });

Where V is the view.

Propably not the nicest way, but it is the easiest! ;)

Black Magic
  • 2,706
  • 5
  • 35
  • 58
0

Looking at your code I am guessing that is an alert box of some sort. If you are using a custom dialog with a custom dialog class then add this line in the onCreate() of your custom dialog class, its been answered here: https://stackoverflow.com/a/53150825/7451779

Haider Malik
  • 1,581
  • 1
  • 20
  • 23