5

मैं अपनी गतिविधि के लिए टैब व्यू को लागू करने की कोशिश कर रहा हूं। मुझे एक त्रुटि मिल रही है जो बताती है।एंड्रॉइड टैबव्यू त्रुटि?

java.lang.IllegalArgumentException: आप टैब सूचक

 Resources res = getResources(); // Resource object to get Drawables 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Resusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent().setClass(this, MonthActivity.class); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("Month") 
         .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, WeekActivity.class); 
     spec = tabHost.newTabSpec("Week") 
       .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, DayActivity.class); 
     spec = tabHost.newTabSpec("Day") 
       .setContent(intent); 
     tabHost.addTab(spec); 
     tabHost.setCurrentTab(2); 

यह मेरा एक्सएमएल है बनाने के लिए एक तरह से निर्दिष्ट करना होगा और मैं प्रकट में क्रियाएँ घोषित कर दिया है।

<?xml version="1.0" encoding="utf-8"?> 
<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:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="5dp" > 

    <TabWidget 
     android:id="@android:id/tabs" 
     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" 
     android:padding="5dp" > 
     </FrameLayout> 
</LinearLayout> 

मैं मेरे गलती कर रहा हूँ? आपके समय और इनपुट के लिए धन्यवाद।

उत्तर

8

इस प्रयास करें:

Resources res = getResources(); // Resource object to get Drawables 
tabHost = getTabHost(); // The activity TabHost 
TabHost.TabSpec spec; // Resusable TabSpec for each tab  
Intent intent; // Reusable Intent for each tab 

intent = new Intent().setClass(this, First.class);  
spec = tabHost.newTabSpec("First Tab").setIndicator("First Tab",res.getDrawable(R.drawable.icon)).setContent(intent); 
tabHost.addTab(spec); 

intent = new Intent().setClass(this, Second.class); 
spec = tabHost.newTabSpec("Second Tab").setIndicator("Second Tab",res.getDrawable(R.drawable.icon)).setContent(intent); 
tabHost.addTab(spec); 

tabHost.setCurrentTab(1); 

और सुनिश्चित करें कि, यदि आपकी गतिविधि में TabActivity जहाँ आप अपने TabHost को परिभाषित किया जाना चाहिए।

4

एक और स्पष्ट और सटीक उत्तर यह है कि आपने TabHost.TabSpec ऑब्जेक्ट पर setIndicator विधि नहीं कहा है, इसलिए यदि आप यह कॉल प्रत्येक टैब स्पेक ऑब्जेक्ट में जोड़ते हैं, तो आपकी समस्या हल हो जाएगी।

spec.setIndicator ("टैब 1");

संबंधित मुद्दे