繁体   English   中英

错误:“您需要指定一种创建Tab指示器的方法”

[英]Error: “You need to specify a way to create Tab indicator”

我正在创建一个TabHost,它是片段中的Tab视图。 子片段将连接到我的主片段fragment_usage 运行后,它一直给我这个错误:

您需要指定一种创建标签指示符的方法。

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

更改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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM