简体   繁体   English

如何通过按回按钮刷新列表视图 - Android

[英]How to refresh listview by hitting back button - Android

I have a ListView that is dynamic and will constantly change. 我有一个动态的ListView,并将不断变化。 The user selects an item and goes to a different activity. 用户选择一个项目并转到另一个活动。

What I want: When they hit back button and return to the ListView, I would like to call a certain action to refresh ListView (in my case an AsyncTask). 我想要的是: 当他们回击按钮并返回ListView时,我想调用某个动作来刷新ListView (在我的例子中是AsyncTask)。

I have figured out one way to do this: By adding my refreshing code in onResume. 我找到了一种方法:在onResume中添加刷新代码。 But I find it refreshes a little too much -- I only want it to refresh when coming from the forward activities. 但是我觉得它有点过分 - 我只是希望它来自前进活动。

I have figured out one way to do this: By adding my refreshing code in onResume. 我找到了一种方法:在onResume中添加刷新代码。 But I find it refreshes a little too much -- I only want it to refresh when coming from the forward activities. 但是我觉得它有点过分 - 我只是希望它来自前进活动。

put your "refresh" code inside of onStart() instead of onResume() . 把你的“刷新”代码放在onStart()而不是onResume() onStart() gets "Called when the activity is becoming visible to the user." onStart()获取“当活动变得对用户可见时调用”。 - Activity Lifecycle - 活动生命周期

Which means that it will happen only at the time that you activity gets put onto the screen. 这意味着它只会在您将活动放到屏幕上时才会发生。

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

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