TouchListView is not working when parent activity finishes

左心房为你撑大大i 提交于 2019-12-12 02:22:49

问题


I'm using a TouchListView by CommonWare and so far it's working fine, But it fails in the following case:

  • activity A has a TouchListView and button to add an item , now when i click over a button,
  • activity B opens up and once the user choose the item i am calling finish to end activity B
  • and it comes back to activity A.

Now here drag n drop in TouchListView doesn't work I mean items are getting dragged but not able to be placed where a user wants, I tried a lot but could not find a way to fix it.


回答1:


I suspect you're doing some setup in onCreate() that's not getting called when you return to Activity A because you're entering it the 2nd (and subsequent) time(s) via onResume().

http://developer.android.com/reference/android/app/Activity.html

BaseAdapter adapter;
List<myStuff> stuffs;

if (adapter == null) {
    adapter = new BaseAdapter()
    if (stuffs == null) {
        stuffs = new List<myStuff>();
    }
}

You're going to need to do something like that and add List to your savedInstanceState bundle in onSaveInstanceState() then dig it out when the activity restarts.



来源:https://stackoverflow.com/questions/15719106/touchlistview-is-not-working-when-parent-activity-finishes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!