简体   繁体   English

Android Endless Listview的屏幕旋转

[英]Screen Rotation with Android Endless Listview

I'm trying the CommonsWare's android endlist adapter. 我正在尝试CommonsWare的android endlist适配器。

https://github.com/commonsguy/cwac-endless https://github.com/commonsguy/cwac-endless

After loading a couple of pages, i rotated the screen, and the listview loses all the pages except the first one. 加载了几页之后,我旋转了屏幕,并且listview丢失了除第一页之外的所有页面。 Doesn't it supposed to retain the loaded items? 它不应该保留已加载的项目吗?

Doesn't it supposed to retain the loaded items? 它不应该保留已加载的项目吗?

That is your job, not the adapter's. 那是您的工作,而不是适配器的工作。 Adapters do not "retain" "items", regardless of whether EndlessAdapter is involved or not. 适配器不“保留”“项目”,无论是否涉及EndlessAdapter

By default, activities are destroyed and recreated when the device undergoes a configuration change, such as a screen rotation. 默认情况下,当设备进行配置更改(例如屏幕旋转)时,活动将被销毁并重新创建。 You need to arrange to hang onto your model data when this occurs, by: 您需要通过以下方式安排挂起模型数据:

  • using setRetainInstance() on a dynamic fragment, or 在动态片段上使用setRetainInstance() ,或
  • using onSaveInstanceState() , or 使用onSaveInstanceState() ,或
  • using onRetainNonConfigurationInstance() , or 使用onRetainNonConfigurationInstance() ,或
  • in the worst case, using android:configChanges , as suggested in another answer 在最坏的情况下,使用android:configChanges ,如另一个答案所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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