我有一个片段活动,它为选定的单个记录加载一整行,第一次工作正常,但如果我改变方向,它会崩溃并抛出“找不到源”。当我逐行调试时,一些TextView不可用(返回null),这是我的片段活动代码:
@Override
public void onCreate(Bundle savedInstanceState)`
{
super.onCreate(savedInstanceState);
setContentView(R.layout.client_layout);
if (savedInstanceState==null)
{
clientActivityViewModel= (ClientActivityViewModel)getLastCustomNonConfigurationInstance();
if(clientActivityViewModel==null)
{
clientActivityViewModel= new ClientActivityViewModel(getBaseContext());
if (bundle== null)
{
bundle= getIntent().getExtras();
}
clientActivityViewModel.setAccountId(bundle.getString("accountId"));
clientActivityViewModel.GetAccountInformation(bundle.getString("accountId"));
clientInformationActivity= new ClientInformationActivity();
clientInformationActivity.setAccountInformation(clientActivityViewModel.getAccountInformation());
clientActivityViewModel.GetAccountComplementaryInformation(bundle.getString("accountId"));
clientComplementaryInformationActivity= new ClientComplementaryInformationActivity();
clientComplementaryInformationActivity.setAccountComplementaryInformation(clientActivityViewModel.getAccountComplementaryInformation());
}
if(clientActivityViewModel!=null)
{
clientActivityViewModel.GetAccountInformation(clientActivityViewModel.getAccountId());
clientInformationActivity= new ClientInformationActivity();
clientInformationActivity.setAccountInformation(clientActivityViewModel.getAccountInformation());
clientActivityViewModel.GetAccountComplementaryInformation(clientActivityViewModel.getAccountId());
clientComplementaryInformationActivity= new ClientComplementaryInformationActivity();
clientComplementaryInformationActivity.setAccountComplementaryInformation(clientActivityViewModel.getAccountComplementaryInformation());
if (clientActivityViewModel != null)
{
pager = (ViewPager) findViewById (R.id.pager);
MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
adapter.addFragment(clientInformationActivity);
adapter.addFragment(clientComplementaryInformationActivity);
adapter.addFragment(new ClientAddressActivity());
adapter.addFragment(new ClientPaymentInfoActivity());
adapter.addFragment(new ClientDescriptionInfoActivity());
pager.setAdapter(adapter);
}
}
}
}
@Override
public Object onRetainCustomNonConfigurationInstance()
{
if (clientActivityViewModel== null)
{
clientActivityViewModel= new ClientActivityViewModel(getBaseContext());
bundle= getIntent().getExtras();
clientActivityViewModel.setAccountId(bundle.getString("accountId"));
}
return clientActivityViewModel;
}