更改方向,失去了我的所有列表项 [英] Changing Orientation, losing all my list items

查看:195
本文介绍了更改方向,失去了我的所有列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我测试我的应用程序在Android设备把我的Andr​​oid手机,从横向到纵向,导致我的列表视图中的所有列表项正在消失。

While I tested my application on an Android Device turning my Android phone from landscape to portrait, results in all the list items in my list view are disappearing.

为什么?

如何管理?

推荐答案

您失去列表中的项目,因为Android的过程中方向改变的默认行为是要摧毁你的活动,并重新创建它。此行为被选择为使机器人重新创建一个新的布局可特别用于新的取向的活性。

You are losing the list items because the default behavior for android during orientation change is to destroy your activity and recreate it. This behavior is chosen to enable android to recreate the activity with a new layout that may be used especially for the new orientation.

要prevent从消失列表项有一些事情必须要做。 首先在方向的变化,有助于该项变更后简单地重复使用相同的活动。这可以通过加入这一行做

To prevent your list items from disappearing there are several thing that have to be done. The first thing that helps during orientation change is to simply reuse the same activity after the change. This can be done through adding this line

android:configChanges="keyboardHidden|orientation"

在你的清单中的活动标签您遇到的问题。对此进行更详细的本<一个解释href="http://stackoverflow.com/questions/2620917/how-to-handle-an-asynctask-during-screen-rotation">question.

如果用户打开该活动,然后将您的应用程序在后台做了很多其他的内存沉重的东西,让您的应用程序从内存中删除,然后重新访问您的应用程序,你解释的行为将有可能也会出现。 如果是这样的话,你必须覆盖的onSaveInstanceState方法,你的活动。 在此<一个是如何这说明href="http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state">question.

The behavior you explained will likely also appear if the user opens the activity and then sends your application to the background does many other memory heavy stuff to get your application removed from memory and then revisits your app. If this is the case you have to overwrite the onSaveInstanceState method in you activity. How to this is explained in this question.

这篇关于更改方向,失去了我的所有列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆