Pregunta

I am using FragmentTabHost for displaying two tabs. Fragment tabs contain various inputs that should be processed in the main activity after menu action. Unfortunately findViewById returns null for views in inactive tab. It is because inactive tab has no view.

See sample code, but I have different FragmentTab implementations for every tab.

Any suggestions how to access views from all tabs?

¿Fue útil?

Solución

I've solved my issue by implementing tabs using (support) ActionBar where I have more control over tab fragments. Instead of detaching I am just hiding them.

Otros consejos

Inactive fragments (not visible at the moment) may not yet have had their xml´s inflated. Therefor the findViewById return null for a element i that xml-view. Maybe you can try

setOffscreenPageLimit()

that tells the tabhost to hold x many tabs "in memory". Eg, for 3 in memory (default is 1)

mTabHost.setOffscreenPageLimit(3)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top