简体   繁体   English

如何将以编程方式创建的视图设置为Tab?

[英]How can i set a programmatically created view to tab?

I am getting the error: 我收到错误消息:

05-14 15:06:13.124: ERROR/AndroidRuntime(2218): Caused by: java.lang.RuntimeException: Could not create tab content because could not find view with id 123 05-14 15:06:13.124:错误/ AndroidRuntime(2218):原因:java.lang.RuntimeException:无法创建选项卡内容,因为找不到ID为123的视图

Why can i not do something like this? 为什么我不能做这样的事情? What am i missing? 我想念什么? Here is the code, basically an RSSview is an extended scrollview with a table layout and rss processor (built programmatically) 这是代码,基本上是RSSview是具有表布局和rss处理器(以编程方式构建)的扩展滚动视图

    final BrRSSView newsView = new BrRSSView(currentActivity,rss);
    newsView.setId(123); 

    tabHost.addTab(
            tabHost.newTabSpec("tab1")
            .setIndicator("Nyheter", getResources().getDrawable(R.drawable.icons_tab_nyheter))
            .setContent(123));

I think the problem is that the TabHost only looks for the view id inside the tabcontent view. 我认为问题是, TabHost仅查找内部视图id tabcontent视图。 If you still want to do this via code, you can add your view to the tabcontent view and then run the addTab() method. 如果仍然要通过代码执行此操作,则可以将视图添加到tabcontent视图中,然后运行addTab()方法。

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

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