简体   繁体   English

Android:帮助使用标签页视图

[英]Android: Help with tabs view

So I'm trying to build a tabs view for an Android app, and for some reason I get a force close every time I try to run it on the emulator. 因此,我试图为Android应用程序构建选项卡视图,由于某种原因,每次尝试在模拟器上运行它时,都会强制关闭。 When I run the examples, everything shows fine, so I went as far as to just about copy most of the layout from the examples(a mix of Tabs2.java and Tabs3.java), but for some reason it still wont run, any ideas? 当我运行示例时,一切都很好,所以我甚至只是从示例中复制了大部分布局(混合了Tabs2.java和Tabs3.java),但是由于某些原因,它仍然无法运行,想法?

Here is my code(List1.class is a copy from the examples for testing purposes). 这是我的代码(List1.class是示例的副本,用于测试)。 It all compiles fine, just gets a force close the second it starts: 一切编译正常,仅在它开始的第二秒得到一个力:

package com.jvavrik.gcm;



import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;

public class GCM extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("g", getResources().getDrawable(R.drawable.star_big_on))
                .setContent(new Intent(this, List1.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("C")
                .setContent(new Intent(this, List1.class))
                );
        tabHost.addTab(tabHost.newTabSpec("tab3")
                .setIndicator("S")
                .setContent(new Intent(this, List1.class))
                );

        tabHost.addTab(tabHost.newTabSpec("tab4")
                .setIndicator("A")
                .setContent(new Intent(this, List1.class))
                );

    }
}

use "adb logcat" console cmd to catch exception message and stack trace from your emulator. 使用“ adb logcat”控制台cmd捕获异常消息和来自模拟器的堆栈跟踪。 it will show you what line of code causes an error 它会告诉您哪一行代码会导致错误

Have you tried setting the current tab with setCurrentTab() or setCurrentTabByTag() after you have defined what each tab will be. 在定义每个选项卡后,是否尝试使用setCurrentTab()或setCurrentTabByTag()设置当前选项卡。 I think at the moment android won't know which one to show first. 我认为目前android不知道首先显示哪个。

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

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