开发者

Lose focus of current activity on device orientation change

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"));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜