是否有可能定义在一个单独的XML文件中每个选项卡的内容? [英] Is it possible to define each tab's content in a separate XML file?

查看:105
本文介绍了是否有可能定义在一个单独的XML文件中每个选项卡的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不同的XML文件来定义每个选项卡的内容,以便在Eclipse中的可视化编辑器都可以使用。也就是说,没有所有的标签被铺设在彼此。可视化编辑器甚至不似乎这里提供的XML示例工作:[链接] [1]
  [1]: http://developer.android.com/guide/tutorials /views/hello-tabwidget.html 这里,它只是一个空指针异常。

我曾尝试在它自己的文件来定义每个抽头,例如:

 <?XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =WRAP_CONTENT
  机器人:layout_height =WRAP_CONTENT>
<的TextView的android:文本=@ + ID / TextView01机器人:ID =@ + ID / TextView01的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< / TextView的>
< / RelativeLayout的>

和添加我使用的标签时:

<$p$p><$c$c>mTabHost.addTab(mTabHost.newTabSpec(\"tab_in\").setIndicator(\"Input\").setContent(R.layout.input));

不过,这会导致崩溃上启动应用程序。有没有办法做到这一点?

感谢


解决方案

只是我的2分钱小费。
我有很多的使用意图基于tabhost问题。
我遇到了非常奇怪的行为expecially用的ListView控件。
我能够摆脱我所有的问题,当我开始重写我的项目进入查看基于tabhost,而不是使用分离意向书/活动

您总是可以有每个标签的分离XML

总之这是我做过什么:

 公共类TabOneView实现TabContentFactory {    私人LayoutInflater mInflater;    公共TabOneView(上下文的背景下){
        mInflater = LayoutInflater.from(上下文);
    }
    @覆盖
    公共查看createTabContent(字符串为arg0){        视图V = mInflater.inflate(R.layout.tab_one,NULL);        / **
         *在这里添加您的code的按钮/表等
         *您按钮的对象查询:
         * /
        按钮B =(按钮)v.findViewById(R.id.btn01);        b.setOnClickListener(mListener);
        //...more code
        返回伏;
    }}

I would like to define each tab's content in a different XML file so the visual editor in Eclipse can be used. That is, without all of the tabs being laid over each other. The visual editor doesn't even seem to work with the XML example provided here: [link text][1] [1]: http://developer.android.com/guide/tutorials/views/hello-tabwidget.html "Here", It just has a Null pointer exception.

I have tried to define each tap in it's own file, for example:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<TextView android:text="@+id/TextView01" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</RelativeLayout>

And when adding the tab I use:

mTabHost.addTab(mTabHost.newTabSpec("tab_in").setIndicator("Input").setContent(R.layout.input));

But this causes the application to crash on launch. Is there any way to do this?

Thanks

解决方案

Just my 2cents. I had lot of problems using an Intent based tabhost. I ran into really strange behaviours expecially with ListView widget. I was able to rid all of my problems when I started to rewrite my project into a View based tabhost instead of using separated Intent/activities

You can always have your separated XML per Tab

In short this is what I did:

public class TabOneView implements TabContentFactory {

    private LayoutInflater mInflater;

    public TabOneView(Context context){
        mInflater = LayoutInflater.from(context);
    }
    @Override
    public View createTabContent(String arg0) {

        View v = mInflater.inflate(R.layout.tab_one, null);

        /**
         * Add your code here for buttons/list etc
         * An object lookup for your Button: 
         */
        Button b = (Button)v.findViewById(R.id.btn01);

        b.setOnClickListener(mListener);
        //...more code
        return v;
    }

}

这篇关于是否有可能定义在一个单独的XML文件中每个选项卡的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆