【问题标题】:cannot resolve symbol android on TabHost methods无法解析 TabHost 方法上的符号 android
【发布时间】:2017-02-23 17:53:23
【问题描述】:

我是 android 开发新手,我正在使用三个选项卡进行 TabHost 布局,所以我制作了我的 xml 文件:

<TabHost
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/ntm">

        <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"
                android:layout_weight="0"/>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:id="@+id/Present"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TableLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                        <TableRow
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <TextView
                                android:text="Simple"
                                android:gravity="center"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:id="@+id/textView24"
                                android:layout_weight="1"/>

                            <TextView
                                android:text="Continuous"
                                android:gravity="center"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:id="@+id/textView23"
                                android:layout_weight="1"/>

                            <TextView
                                android:text="Perfect Simple"
                                android:gravity="center"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:id="@+id/textView15"
                                android:layout_weight="1"/>

                            <TextView
                                android:text="Perfect Continuous"
                                android:gravity="center"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:id="@+id/textView8"
                                android:layout_weight="1"/>
                        </TableRow>

                        <TableRow
                            android:layout_width="match_parent"
                            android:layout_height="match_parent" />

                    </TableLayout>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/Past"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:text="NTM1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/textView25" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/Future"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:text="NTM2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/textView26" />
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>
</LinearLayout>

这是我在相关活动中初始化选项卡的代码:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.time);

    }
    TabHost tab =(TabHost) findViewById(R.id.ntm);
    tab.setup();

    TabHost.TabSpec spec1 = tab.newTabSpec("PRESENT");
    spec1.setIndicator("PRESENT");
    spec1.setContent(R.id.Present);
    tab.addTab(spec1);

    TabHost.TabSpec spec2 = tab.newTabSpec("PAST");
    spec2.setIndicator("PAST");
    spec2.setContent(R.id.Past);
    tab.addTab(spec2);

    TabHost.TabSpec spec3 = tab.newTabSpec("FUTURE");
    spec3.setIndicator("FUTURE");
    spec3.setContent(R.id.Future);
    tab.addTab(spec3);

我得到这个错误:

无法解析符号

适用于tab.setup() 等所有方法或适用于TabHostTabSpec 对象的所有方法。

我尝试将我的代码复制/粘贴到 main activity 中,没有任何错误,但应用程序立即崩溃

【问题讨论】:

    标签: java android android-layout android-studio


    【解决方案1】:

    我发现我的错误,我没有将初始化代码放入方法onCreate我没有更多错误

    【讨论】:

      猜你喜欢
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多