के बाद टैबहोस्ट फ्रैगमेंट में मैपएक्टिविटी गायब हो रही है, मैं टुकड़ों का उपयोग करके टैब के एक सेट में एक नक्शा प्रदर्शित करने की कोशिश कर रहा हूं। मेरी समस्या यह है कि यदि उपयोगकर्ता किसी अन्य खंड में वापस जाता है तो नक्शा गतिविधि गायब हो जाती है। मैं टैबहोस्ट में टुकड़ों में मैपएक्टिविटी कैसे प्रदर्शित कर सकता हूं?टैब स्विच
इस के लिए आधार कैसे टुकड़े के साथ एक MapActivity एकीकृत करने के लिए आसपास कई सवालों से है (MapView in a Fragment (Honeycomb) देखें)
MainTabActivity एक tabhost है और टैब में टुकड़े प्रदर्शित करने के लिए FragmentManager उपयोग करता है। मैपफ्रैगमेंट में एक टैबहोस्ट है और मैपएक्टिविटी प्रदर्शित करने के लिए इसका उपयोग करता है।
मैपफ्रैगमेंट स्थानीय गतिविधि प्रबंधक का उपयोग जीवन चक्र घटनाओं को निहित गतिविधि में प्रचारित करने के लिए करता है।
तो MapFragment:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.map_fragment, container, false);
mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
mTabHost.setup(getLocalActivityManager());
Intent intent = new Intent(getActivity(), MapActivityWrapper.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//does nothing
TabHost.TabSpec tab = mTabHost.newTabSpec("map")
.setIndicator("map")
.setContent(intent);
mTabHost.addTab(tab);
return view;
}
MapFragment लेआउट:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
</LinearLayout>
टैब सामग्रियों को परिवर्तित करने के लिए MainTabActivity में कोड:
private void updateTab(String oldId, String tabId) {
FragmentManager fm = getSupportFragmentManager();
Fragment old = fm.findFragmentByTag(oldId);
Fragment selected = fm.findFragmentByTag(tabId);
FragmentTransaction ft = fm.beginTransaction();
boolean added = false;
if (selected == null) {
selected = createFragment(tabId);
} else {
try {
ft.remove(selected);
} catch (Exception e) {
ft.add(android.R.id.tabcontent, selected, tabId);
added = true;
//exception for removing an unadded fragment... why throw an exception?
}
}
if (old != null) ft.remove(old);
if (!added) ft.replace(android.R.id.tabcontent, selected, tabId);
if (!creating && !backStackProcessing) ft.addToBackStack(null);//member vars
ft.commit();
}
MainTabActivity लेआउट (असंबंधित लेआउट का एक समूह को नष्ट कर दिया):
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EFEFEF">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_gravity="top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/app_default_bg"
android:layout_above="@+id/ad_region"
android:layout_below="@+id/quick_action_region">
<FrameLayout android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<FrameLayout android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<FrameLayout android:id="@+id/map_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<FrameLayout android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
<TabWidget android:layout_width="fill_parent"
android:id="@android:id/tabs"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"/>
</RelativeLayout>
</TabHost>
फिर से - मेरी समस्या यह है कि यदि उपयोगकर्ता किसी अन्य खंड में वापस जाता है तो नक्शा गतिविधि गायब हो जाती है। मैं टैबहोस्ट में टुकड़ों में मैपएक्टिविटी कैसे प्रदर्शित कर सकता हूं?
बहुत धन्यवाद।
क्या आपने इस समस्या को हल करने का अंत किया? मैं एक ही समस्या के खिलाफ दौड़ रहा हूँ ... – Rockmaninoff