Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Listview not shifting up with keyboard

My layout looks like this:

<LinearLayout>
  <RelativeLayout>
    Some Image and Text as Title
  </RelativeLayout>
  <RelativeLayout>
    <LinearLayout>
      <ListView>
        My message List
      </ListView>
    </LinearLayout>
    <RelativeLayout>
      Edit Box and Send Button
    </RelativeLayout>
  </RelativeLayout>
</LinearLayout>

I explicitly set the current selection to the last item (newest) of the list when showing.

When not entering text in the Edit box at the bottom, the screen looks like this:

Top Title
  List Item 8
  List Item 7
  ...
  List Item 2
  List Item 1
  Bottom Edit box and Send Button

When I click on the Edit box to type my message, the screen looks like this:

Top Title
  List Item 8
  ...
  List Item 5
  Bottom Edit Box and Send Button
  Keyboard

What I really want is:

Top Title
  List Item 4
  ...
  List Item 1
  Bottom Edit Box and Send Button
  Keyboard

Can someone help me please?

like image 287
radium22 Avatar asked Jun 24 '11 16:06

radium22


2 Answers

I found the answer here.

Basically just extend ListView with your custom class, override the onSizeChanged() method to setSelection(getCount());

This seems to be the best solution, and it appears Google Voice uses the same tactic (because if you're at the top of the chat list, then rotate the screen, it puts you back at the bottom).

Also remember that android:windowSoftInputMode="adjustResize" is present instead of adjustPan in your activity's tags in your manifest.

like image 167
Weston Avatar answered Nov 16 '22 18:11

Weston


Did you try this?

You would need to use setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL) and setStackFromBottom(true) in your list. Hope it helps, it worked for me!

like image 2
Juan Carlos Piñeros Avatar answered Nov 16 '22 18:11

Juan Carlos Piñeros