简体   繁体   中英

ListView jumps to top on modifying footer

I'm trying to create a simple chat layout.

I have a ListView with transcriptMode="alwaysScroll" and setStackFromBottom(true). The ListView has a footer with an EditText and a button (It's a footer because I want it to scroll with the list).

Whenever the user types in the EditText i change the text on the button, using a TextWatcher.

The problem is that when using a physical keyboard, every letter typed scrolls the list to the top, and prevents additional letters to get into the EditText. It works fine with soft keyboard...

I've thought it might be related to the footer being changes calling the adapter to refresh, but it doesn't seem to be that.

Is this an Android bug or am I missing something?

Thanks.

EDIT: Another important thing I forgot to add, and is very weird, when typing any letter is scrolls to top, but when deleting characters it works ok, the same afterTextChanged gets called.

Well, looks like I've solved it,

The afterTextChanged forced a re-layout in the ListView causing it to jump to top (which should have been jump to bottom because I've set stackFromBottom).

Anyway, I've switched some views from wrap_content to other alternatives, and switched from using visibility 'gone' on hidden views to 'invisible' so that the onMeasure wouldn't have to be called after every letter and it worked.

Hope this helps someone...

See whether this helps via this site

//Here is where the magic happens
02  this.getListView().setOnScrollListener(new OnScrollListener(){
03   
04      //useless here, skip!
05      @Override
06      public void onScrollStateChanged(AbsListView view, int scrollState) {}
07   
08      //dumdumdum
09      @Override
10      public void onScroll(AbsListView view, int firstVisibleItem,
11          int visibleItemCount, int totalItemCount) {
12   
13          //what is the bottom iten that is visible
14          int lastInScreen = firstVisibleItem + visibleItemCount;            
15   
16          //is the bottom item visible & not loading more already ? Load more !
17          if((lastInScreen == totalItemCount) && !(loadingMore)){
18              Thread thread =  new Thread(null, loadMoreListItems);
19              thread.start();
20          }
21      }
22  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM