Abhishek
Abhishek

Reputation: 25

listview auto scroll on keyboard popup android

I have a view with a listview, one edit text and one button. I am using this code to autoscroll listview to the bottom

listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

but what happens is if I srcoll the listview to any position and click on edit text it will scroll down to bottom. I want it like its in any other apps for eg whatsapp. Listview should be there in its position where its scrolled currently. It should not go to bottom unless its scrolled to the buttom or the listview is opened for first time. Same way it works in whatsapp.

I also tried this code but it works same way :-

public class CustomListView extends ListView {

public CustomListView (Context context) {
    super(context);
}

public CustomListView (Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomListView (Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) {
    super.onSizeChanged(xNew, yNew, xOld, yOld);

    post(new Runnable() {
        public void run() {
            setSelection(getCount());
        }
    });
}

}

how do I do that. Thanks

Upvotes: 1

Views: 1544

Answers (1)

Simas
Simas

Reputation: 44118

Try using:

listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);

Upvotes: 4

Related Questions