我有一个ViewGroup
,如果我的活动充气,它会触发onRestoreInstanceState()
setContentView()
。如果我尝试使用getLayoutInflater().inflate()
对其进行充气,则不会。{/ p>
我试图像Restoring view hierarchy from saved state does not restore views added programatically中所述设置ID。我在布局文件中也有一个ID,getID()
返回相同的每个活动重新创建,但它不会恢复也不会保存实例状态。
我怎样才能克服这个?
(编辑)目前我正在使用的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.main); //this code will work as intended
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
View content = getLayoutInflater().inflate(R.layout.main, null);
setContentView(content); //this code will also work
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.another_layout);
View content = getLayoutInflater().inflate(R.layout.main, null); //now this view won't fire the method
}
关键是我不想将该视图用作活动的布局。我需要以其他方式充气。