spa*_*rky 4 android android-tabhost android-3.0-honeycomb
我对Honeycomb的向后兼容性有疑问.我有一个支持2.1或更高版本的应用程序,似乎主要在Honeycomb上工作,除非他们启动TabActivity.
特别是,当我向TabHost添加标签时,我得到以下异常
android.content.res.Resources $ NotFoundException:资源ID#0x0
在查看抛出此异常的代码时,我发现它是带有标签和图标的选项卡规范.在代码内部,LabelAndIconIndicatorStrategy尝试对布局文件R.layout.tab_indicator进行充气,该文件似乎不可用.
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(_gameActivity, ScoreGameActivity.class);
intent.putExtra(GameChangerConstants.STREAM_ID, _stream.pk().toString());
// Initialize a TabSpec for each tab and add it to the TabHost
spec = _gameTabHost.newTabSpec("score_game").setIndicator("Score", res.getDrawable(R.drawable.icon_field_gloss)).setContent(intent);
_gameTabHost.addTab(spec);
Run Code Online (Sandbox Code Playgroud)
有没有为蜂窝创建标签的新方法,我不知道?我已经倾倒了文档,但没有看到任何表明我所做的事情的问题.
在此之前,我想避免使用片段,直到我们可以对UI小部件进行更全面的重构,并且我希望更好地理解这个问题.
plo*_*man 14
我相信我找到了一个解决方案,但是因为人们很好奇,这是我遇到这个问题时得到的堆栈跟踪:
05-17 13:09:53.462: ERROR/CustomExceptionHandler(500): Uncaught throwable in thread Thread[main,5,main]
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1014)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2039)
at android.content.res.Resources.getLayout(Resources.java:853)
at android.view.LayoutInflater.inflate(LayoutInflater.java:389)
at android.widget.TabHost$LabelAndIconIndicatorStrategy.createIndicatorView(TabHost.java:568)
at android.widget.TabHost.addTab(TabHost.java:226)
at com.myApp.ui.TabDialog.addTab(TabDialog.java:80)
...
Run Code Online (Sandbox Code Playgroud)
在那一行,我的代码大致相当于闪闪发光的东西:
spec = myTabHost.newTabSpec("score_game").setIndicator("Score", res.getDrawable(R.drawable.icon_field_gloss)).setContent(intent);
myTabHost.addTab(spec);
Run Code Online (Sandbox Code Playgroud)
请注意,这myTabHost是spec一个TabHost 并且是一个TabSpec.
以前,我这样初始化myTabHost:
//WRONG - This can CRASH your app starting at Android SDK 3.0
TabHost myTabHost = new TabHost(getContext());
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我开始通过这样做来初始化TabHost:
TabHost myTabHost = new TabHost(getContext(), null);
Run Code Online (Sandbox Code Playgroud)
那就解决了!我很想找到根本原因,但我还没有弄清楚.
| 归档时间: |
|
| 查看次数: |
3041 次 |
| 最近记录: |