Android Question Final item in Listview disappears when phone rotates

Dan Haugland

Member
Licensed User
Simple app with a tabstrip, second tab has a listview. When phone rotates from portrait to landscape the listview has 1 less item. There are portrait and landscape variants of the layout defined. Why?
 

Dan Haugland

Member
Licensed User
THanks for the example, yours works, but it uses tabhost instead of tabstrip. When I changed it to use tabstrip, it still worked as intended, so I added a service and moved the code to populate the listview into there, and finally it's broken. I'm using one of the tabs to concatenate status information gathered from both the main activity and a service. What this shows is that when rotating, the content added from the service (via callsubdelayed2) disappears from the listview. In my original post, the last line in the listview is added via the service, while the other stuff was from main activity, consistent with this example.

What am I doing wrong that it's fine in portrait and not so in landscape? Zip attached
 

Attachments

  • tstripsvc.zip
    9.9 KB · Views: 98
Upvote 0

LucaMs

Expert
Licensed User
Service_Create starts one time only. If you rotate the device, the Activity will be created again but the service, still running, will not fill the listview.

You can simply stop the service before starting it:
StopService(svc)
StartService(svc)

It works in this case, but probably you will need to fill the listview in from elsewhere.

BTW, on my tablet the listview items are too small.
 
Upvote 0

Dan Haugland

Member
Licensed User
Ah, because the rotation destroys and recreates the activity containing the listview. That makes sense except...why do any items added in the main activity remain in the listview after rotation?

Ah, artifact of the way the example is build....activity create is adding those again for me. Think I have it, thanks for the clarity.
 
Last edited:
Upvote 0
Top