Why is android:transcriptMode="normal" not working properly?

Posted by BCS on Stack Overflow See other posts from Stack Overflow or by BCS
Published on 2011-04-02T05:47:10Z Indexed on 2011/11/18 9:50 UTC
Read the original article Hit count: 159

Filed under:
|

I've been doing a lot of fiddling with an issue I've been having. What happens is each time an item gets added to my listview (adapter) I expect it to auto-scroll if I'm at the last item (which it will do to an extent); HOWEVER, if 3 or more items get added at once, it will not auto-scroll.

Here is the XML of that listview:

    <ListView android:id="@android:id/list"
    android:layout_width="fill_parent" 
    android:layout_height="0dip"
    android:layout_weight="1"
    android:transcriptMode="normal"/>

I tried a workaround using a snippet I found here.

My code is as follows:

public void addChat(final String text, final String username) {
    this.runOnUiThread(new Runnable() {
        public void run() {
            globals.chatAdapter.add(DateFormat.format("hh:mmaa", Calendar.getInstance()).toString(), username, text);

            globals.chatAdapter.notifyDataSetChanged();

            int lastP = getListView().getLastVisiblePosition();
            int count = globals.chatAdapter.getCount() - 1;

            if (lastP == globals.chatAdapter.oldP || lastP == -1) {
                getListView().setSelection(count);
            }

            globals.chatAdapter.oldP = count;
        }
    });
}

The problem with this is when a bunch of items come in at once, getListView().getLastVisiblePosition() will not update right away causing a setSelection() to never get called, and thus no auto-scroll.

Any suggestions?

© Stack Overflow or respective owner

Related posts about android

Related posts about android-layout