错误:“您需要指定一种创建Tab指标的方法”(Error: “You need to specify a way to create Tab indicator”)

编程入门 行业动态 更新时间:2024-10-11 13:28:16
错误:“您需要指定一种创建Tab指标的方法”(Error: “You need to specify a way to create Tab indicator”)

我正在创建一个TabHost,它是一个片段中的Tab视图。 子片段将连接到名为fragment_usage主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

I am creating a TabHost which is a Tab view in a fragment. The sub fragment will be connected to my main fragment called fragment_usage. After running, it keeps giving me this error:

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

最满意答案

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

Change spec1-> spec2,spec3,spec4; Be careful when you are copying :)

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

更多推荐

本文发布于:2023-07-30 15:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338752.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:您需要   指标   错误   方法   create

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!