2016-02-26 64 views
0

我正在创建一个TabHost,它是一个片段中的选项卡视图。子片段将连接到我的主要片段fragment_usage。运行后,它不断给我这个错误:错误:“您需要指定一种方法来创建选项卡指示器”

you need to specify a way to create tab indicator.

MAIN FRAGMENT(FRAGMENT_USAGE) 

package com.example.redir.wealthtrack; 


import android.content.DialogInterface; 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.TabHost; 

import com.example.redir.wealthtrack.Tabs.Tag1; 


/** 
* A simple {@link Fragment} subclass. 
*/ 
public class UsageFragment extends Fragment { 


    public UsageFragment() { 
     // Required empty public constructor 
    } 


    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.fragment_usage, container, false); 
     TabHost tab = (TabHost) view.findViewById(R.id.tabHost); 
     tab.setup(); 

     TabHost.TabSpec spec1 = tab.newTabSpec("Tab 1"); 
     spec1.setIndicator("Tab 1"); 
     spec1.setContent(R.id.Tab1); 
     tab.addTab(spec1); 

     TabHost.TabSpec spec2 = tab.newTabSpec("Tab 2"); 
     spec1.setIndicator("Tab 2"); 
     spec1.setContent(R.id.Tab2); 
     tab.addTab(spec2); 

     TabHost.TabSpec spec3 = tab.newTabSpec("Tab 3"); 
     spec1.setIndicator("Tab 3"); 
     spec1.setContent(R.id.Tab3); 
     tab.addTab(spec3); 

     TabHost.TabSpec spec4 = tab.newTabSpec("Tab 4"); 
     spec1.setIndicator("Tab 4"); 
     spec1.setContent(R.id.Tab4); 
     tab.addTab(spec4); 


       return view; 


    } 
} 
[enter image description here][1] 


    [1]: http://i.stack.imgur.com/hLyii.png 

回答

0

变化spec1-> SPEC2,SPEC3,spec4;当你复制时要小心:)

TabHost.TabSpec spec1 = tab.newTabSpec("Tab 1"); 
    spec1.setIndicator("Tab 1"); 
    spec1.setContent(R.id.Tab1); 
    tab.addTab(spec1); 

    TabHost.TabSpec spec2 = tab.newTabSpec("Tab 2"); 
    spec2 .setIndicator("Tab 2"); 
    spec2 .setContent(R.id.Tab2); 
    tab.addTab(spec2); 

    TabHost.TabSpec spec3 = tab.newTabSpec("Tab 3"); 
    spec3 .setIndicator("Tab 3"); 
    spec3 .setContent(R.id.Tab3); 
    tab.addTab(spec3); 

    TabHost.TabSpec spec4 = tab.newTabSpec("Tab 4"); 
    spec4 .setIndicator("Tab 4"); 
    spec4 .setContent(R.id.Tab4); 
    tab.addTab(spec4); 
相关问题