错误:“您需要指定一种创建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:
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.pngyou need to specify a way to create tab indicator.
最满意答案
更改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);更多推荐
发布评论