在活动Android的ListView中得到刷新上更改方向方向、Android、ListView

2023-09-04 11:23:04 作者:刺心

我有一个的ListView里面,并在活动我有$ C $下填充的ListView这一数据的数据的onCreate方法活动是一种基于服务器等填充包括呼叫网络的网址。我有相同的活动类的ListView的一个ArrayAdapter。

I have Activity with ListView inside it and in the onCreate method of the Activity I have code for populating the Data of the ListView this Data is a server based and so populating includes calling Network URLs. I have the ArrayAdapter of the ListView in the Same Activity Class.

现在我'所面临的问题是,在休息所有方案我的活动是表现在一个适当的方式,但在方向[纵向舍景观美化或其他方式]正在发生的数据迷路,更新的数据呼叫需要填充相同的旧数据,现在这是一件不打算出code我应该怎么处理它。

Now the Issue I'am facing is that, in Rest all scenarios my Activity is behaving in a proper way but when the Orientation [ Portrait to Landscaped or other way round] is taking place the Data is Getting lost and Newer Data calls are Required to Populate the Same Old Data now this is something that is not intended out the code how should I deal with it.

推荐答案

Android将停止并重新启动您的活动,除非你告诉它,你会处理的方向改变自己。它这样做,这样你可以指定不同的资源(比如布局)是定位特定的(以及其他原因)。

Android will stop and restart your activity unless you've told it you will handle orientation changes yourself. It does this so that you can specify different resources (such as layouts) that are orientation-specific (among other reasons).

您需要添加android:configChanges="orientation"为您的活动delcaration在AndroidManifest.xml中,你需要重写onConfigurationChanged().我不相信你需要做什么特别的事情里面onConfigurationChanged(),简单地实现它应该做的伎俩。

You need to add android:configChanges="orientation" to your activity delcaration in your AndroidManifest.xml, and you need to override onConfigurationChanged(). I don't believe you need to do anything special inside onConfigurationChanged(), simply implementing it should do the trick.