Mi main activity is a TabActivity tha开发者_C百科t launches an intent TabGroup activity, this tabGroup starts a child activity, this child activity is a Listview with several options. And now, if you select some option from the listview and change the device orientation, I lose focus from the current activity because the oncreate() from the TabGroup is called, there is any way to prevent this? Many thanks for the help!.
The activity gets shut down and restarted on orientation change.
use onSaveInstanceState(Bundle)
to store the selected option and restore that selection in onCreate(Bundle)
.
i.e.
onSaveInstanceState(Bundle bundle) {
bundle.putInt("selected", listView.getSelectedItemPosition());
}
onCreate(Bundle bundle) {
if (bundle.containsKey("selected")) {
listView.setSelection(bundle.getInt("selected"));
}
精彩评论