문제

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