I have a fragment with ListView and ArrayAdapter as global variables in custom fragment class. I also have a function that should update this list making additional text field visible or not. So if I call list update function after rotate (with changing to special land layout) from activity, I found ListView and ArrayAdapter objects are null. Therefore I can't update my list. What should I do? Thnx guys.
private View fragmentView;
private SimpleListNewsAdapter adapterNews;
private ListView listNews;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragmentView = inflater.inflate(getLayoutId(), container, false);
listNews = (ListView) fragmentView.findViewById(R.id.newsList);
adapterNews = new SimpleListNewsAdapter(fragmentView.getContext(), R.id.newsList);
listNews.setAdapter(adapterNews);
…
return fragmentView;
}
public void showListExpanded(Boolean expanded){
if (isShowDesc != expanded){
isShowDesc = expanded;
if (adapterNews != null && listNews != null){
adapterNews.notifyDataSetChanged();
listNews.refreshDrawableState();
listNews.invalidateViews();
listNews.setAdapter(adapterNews);
} else {
// Here I should do something to refresh my list
}
}
}