Android标签布局错误

时间:2011-08-01 05:30:45

标签: android layout tabs

新手在这里......

我正在尝试学习并使标签布局正常工作(如here所示),但遇到了一些错误。除以下情况外,所有问题都已得到解决:

[ArtistsActivity无法解析为某种类型。]

我得到以下内容:

ArtistsActivity.class
AlbumsActivity.class
SongsActivity.class

我该如何解决这个问题?

感谢您的帮助。

(今年秋季学期要注册Java课程。)

HelloTabWidget.java

package com.HelloTabWidget.tabs;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;



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

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, ArtistsActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("artists").setIndicator("Artists",
                          res.getDrawable(R.drawable.ic_tab_artists))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, AlbumsActivity.class);
        spec = tabHost.newTabSpec("albums").setIndicator("Albums",
                          res.getDrawable(R.drawable.ic_tab_artists))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, SongsActivity.class);
        spec = tabHost.newTabSpec("songs").setIndicator("Songs",
                          res.getDrawable(R.drawable.ic_tab_artists))
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(2);
    }
}    

1 个答案:

答案 0 :(得分:1)

尝试使用此方法来调用意图位置

    Intent showContent = new Intent(getApplicationContext(),ArtistsActivity.class);
    startActivity(showContent);