क्या मेजबान को तुरंत उन्हें बनाने के लिए मजबूर करने का कोई तरीका है कि मैं सुरक्षित रूप से getFragmentByTag द्वारा उन्हें एक्सेस कर सकता हूं?
संख्या क्योंकि लेनदेन onAttachedToWindow()
पर निष्पादित किया गया है। जैसा कि आप देख mFragmentManager.executePendingTransactions();
onAttachedToWindow
पर निष्पादित किया जाता है
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
String currentTab = getCurrentTabTag();
// Go through all tabs and make sure their fragments match.
// the correct state.
FragmentTransaction ft = null;
for (int i=0; i<mTabs.size(); i++) {
TabInfo tab = mTabs.get(i);
tab.fragment = mFragmentManager.findFragmentByTag(tab.tag);
if (tab.fragment != null && !tab.fragment.isDetached()) {
if (tab.tag.equals(currentTab)) {
// The fragment for this tab is already there and
// active, and it is what we really want to have
// as the current tab. Nothing to do.
mLastTab = tab;
} else {
// This fragment was restored in the active state,
// but is not the current tab. Deactivate it.
if (ft == null) {
ft = mFragmentManager.beginTransaction();
}
ft.detach(tab.fragment);
}
}
}
// We are now ready to go. Make sure we are switched to the
// correct tab.
mAttached = true;
ft = doTabChanged(currentTab, ft);
if (ft != null) {
ft.commit();
mFragmentManager.executePendingTransactions();
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mAttached = false;
}
: source code पर एक नजर है की सुविधा देता है।
या क्या टैब "मेरे अपने" पर बनाना संभव है और बस उन्हें टैबहोस्ट में जोड़ें?
हाँ, आप tabhost का उपयोग कर सकते हैं और आप नीचे विधियों के साथ टैब सामग्री बना सकते हैं।
public TabHost.TabSpec setContent (int viewId)
public TabHost.TabSpec setContent (Intent intent)
public TabHost.TabSpec setContent (TabHost.TabContentFactory contentFactory)
यदि आप शुरू में फोन 'onTabChanged (tabId)' हर टैब के लिए (वर्तमान से एक के लिए स्विच करने से पहले), तो यह है कि 'FragmentTabHost' बाध्य करेगा पूर्व सभी टुकड़ों को दोहराएं। यदि आप खंड कंटेनर की आईडी प्राप्त करते हैं, तो आप इसे स्वयं भी कर सकते हैं। वैकल्पिक रूप से, आप अपने वांछित व्यवहार को लागू करने के लिए इसे बढ़ा सकते हैं या फोर्क कर सकते हैं। – corsair992