I've been experiencing a very weird bug lately... and simply don't know what to do...
I have a "Tabbed-Fragment-Activity", which means I needed a tabhost on the bottom so I used google's API example, which manages fragments via the TabHost (& Manager) Almost each tab is actually a ListFragment and to each I add an header at "OnActivityCreated".
Now the weird thing is : When i move to a tab (ListFragment) the first time, I can see the header, but once I move from the tab and afterwards move back to it, the header is GONE !!!
This is the code I'm using :
private boolean initialized = false;
private TextView m_Header = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
String listTitle = "HELLO HUMAN"
if(m_Header == null && !Helpers.isNullOrBlank(listTitle))
{
m_Header = (TextView)inflater.inflate(R.layout.newslist_header, null, false);
m_Header.setText(listTitle);
}
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if(!initialized)
{
ListView list = getListView();
if(m_Header != null)
{
list.addHeaderView(m_Header);
}
this.m_adapter = new SomeAdapter();
setListAdapter(this.m_adapter);
registerForContextMenu(list);
this.initialized = true;
}
}
I'm using this "initialized" boolean as to not call "setListAdapter"/"addHeader" each time I load the fragment (otherwise you get a nasty exception saying you can't add header after setting the adapter...)
Errr... i'm clueless @ this point...
please help :)