ListView 修改页脚时跳转到顶部

发布于 2024-12-07 21:57:54 字数 451 浏览 0 评论 0原文

我正在尝试创建一个简单的聊天布局。

我有一个带有transcriptMode =“alwaysScroll”和setStackFromBottom(true)的ListView。 ListView 有一个带有 EditText 和按钮的页脚(它是页脚,因为我希望它随列表滚动)。

每当用户在 EditText 中键入内容时,我都会使用 TextWatcher 更改按钮上的文本。

问题是,当使用物理键盘时,输入的每个字母都会将列表滚动到顶部,并阻止其他字母进入 EditText。 它与软键盘配合得很好...

我认为这可能与页脚更改调用适配器刷新有关,但似乎并非如此。

这是 Android 的错误还是我遗漏了什么?

谢谢。

编辑: 我忘记添加的另一件重要的事情很奇怪,当输入任何字母时滚动到顶部,但是当删除字符时它工作正常,相同的 afterTextChanged 被调用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

壹場煙雨 2024-12-14 21:57:54

好吧,看起来我已经解决了这个问题,

afterTextChanged 强制在 ListView 中重新布局,导致它跳到顶部(应该跳到底部,因为我设置了 stackFromBottom)。

不管怎样,我已经将一些视图从wrap_content切换到其他替代方案,并将隐藏视图上的可见性“消失”切换为“不可见”,这样就不必在每个字母之后调用onMeasure并且它起作用了。

希望这对某人有帮助...

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...

梦醒灬来后我 2024-12-14 21:57:54

看看这是否有帮助 通过这个网站

//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  });

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  });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文