【发布时间】:2012-03-24 12:04:53
【问题描述】:
多年来,我一直在尝试解决此问题,在 android 的选项卡教程中,我完全遵循了它,但在我的 TabWidget.java 类上不断收到此错误消息。
R.drawable.ic_tab_albums 无法解析
tabWidget.java/HelloTabWidget/src/com/example/tabwidget
和
R.drawable.ic_tab_songs 无法解析
tabWidget.java/HelloTabWidget/src/com/example/tabwidget
这是我的 TabWidget.java 类的代码
`
导入 com.example.androidtab.R;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class TabWidget extends Activity {
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_albums))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
private TabHost getTabHost() {
// TODO Auto-generated method stub
return null;
}
}`
【问题讨论】:
-
特别参考 KevinDTimm 链接到的 Ted 的答案。它指出本教程没有指示您创建使该示例正常工作所需的其他 2 个 xml 文件。