2013-02-03 24 views
5

Tôi nhận được "bạn phải chỉ định cách tạo lỗi chỉ báo tab" (theo logcat). Không thể tìm ra lý do.Không thể tìm thấy nguyên nhân "bạn phải chỉ định cách tạo chỉ báo tab"

lớp chính:

package org.tatvamoksh.tml; 


import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Window; 
import android.widget.TabHost; 
import android.widget.TabHost.TabSpec; 

@SuppressWarnings({ "deprecation" }) 
public class MainActivity extends TabActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    //Remove title bar 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

    setContentView(R.layout.activity_main); 

    TabHost tabHost = getTabHost(); 

    // Tab for Tatva 
    TabSpec t = tabHost.newTabSpec("Tatva"); 
    // setting Title and Icon for the Tab 
    t.setIndicator("Tatva"); 
    Intent tatvaIntent = new Intent(this, TatvaActivity.class); 
    t.setContent(tatvaIntent); 

    // Tab for Moksh 
    TabSpec m = tabHost.newTabSpec("Moksh"); 
    m.setIndicator("Moksh"); 
    Intent mokshIntent = new Intent(this, MokshActivity.class); 
    m.setContent(mokshIntent); 

    //Tab for Updates 
    TabSpec u = tabHost.newTabSpec("Updates"); 
    m.setIndicator("Updates"); 
    Intent updatesIntent = new Intent(this, Updates.class); 
    m.setContent(updatesIntent); 

    // Adding all TabSpec to TabHost 
    tabHost.addTab(t); // Adding Tatva tab 
    tabHost.addTab(m); // Adding Moksh tab 
    tabHost.addTab(u); // Adding Updates tab 
} 
} 

bố trí file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

<TabHost 
android:id="@android:id/tabhost" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

     <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

     <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

      <ListView 
      android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 
      </ListView> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 
</RelativeLayout> 

Bình luận ra đoạn mã sau sửa chữa nó.

 //Tab for Updates 
    TabSpec u = tabHost.newTabSpec("Updates"); 
    m.setIndicator("Updates"); 
    Intent updatesIntent = new Intent(this, Updates.class); 
    m.setContent(updatesIntent); 

Tôi không thể đoán được vấn đề chính xác. Sẽ biết ơn đối với bất kỳ hướng dẫn nào.

Trả lời

7

thay đổi tab cuối cùng mã như:

//Tab for Updates 
    TabSpec u = tabHost.newTabSpec("Updates"); 
    u.setIndicator("Updates"); 
    Intent updatesIntent = new Intent(this, Updates.class); 
    u.setContent(updatesIntent); 

vì bạn không thiết lập chỉ số và nội dung cho TabSpec u (bạn đang thiết cho m Tab)

+0

Ahhh ... làm thế nào tôi có thể bỏ lỡ. Cảm ơn rất nhiều :) – hypd09

+0

@spexy: bạn thân nhất –

Các vấn đề liên quan