質問

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?

役に立ちましたか?

解決

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.

他のヒント

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)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top