2011-08-01 79 views
0

新手在這裏...Android的標籤佈局錯誤

我想既學習並獲得該選項卡布局工作(如圖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); 
    } 
}  
+0

什麼是你的第一個錯誤 –

回答

1

嘗試這樣調用的意圖地方

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