本文介绍了找不到原因和QUOT;您必须指定一个方法来创建选项卡指示器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到您必须指定一个方法来创建选项卡指示器的错误(根据logcat中)。找不到原因。
I am getting "you must specify a way to create the tab indicator" error(as per logcat).Can't find the reason.
主要类:
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
}
}
布局文件:
<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>
注释掉以下code修复它。
Commenting out the following code fixes it.
//Tab for Updates
TabSpec u = tabHost.newTabSpec("Updates");
m.setIndicator("Updates");
Intent updatesIntent = new Intent(this, Updates.class);
m.setContent(updatesIntent);
我无法猜测确切的问题。我们将非常感谢任何指导。
I can't guess the exact problem. Would be grateful for any guidance.
推荐答案
改变最后一个标签code为:
change last tab code as :
//Tab for Updates
TabSpec u = tabHost.newTabSpec("Updates");
u.setIndicator("Updates");
Intent updatesIntent = new Intent(this, Updates.class);
u.setContent(updatesIntent);
由于您没有设置指标和内容则tabspec U
(您正在设置对于M标签)
because you are not setting Indicator and Content for TabSpec u
(you are setting for m Tab)
这篇关于找不到原因和QUOT;您必须指定一个方法来创建选项卡指示器&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!