有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我正在尝试在选项卡上插入一个编辑文本框

我正在做一个安卓项目,我有四个标签。在其中一个选项卡上,我试图插入一个编辑字段框。有没有关于怎么做的线索

这是我的主要观点。xml文件:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:id="@安卓:id/tabhost"
    安卓:layout_width="fill_parent"
    安卓:layout_height="fill_parent">
    <LinearLayout
        安卓:orientation="vertical"
        安卓:layout_width="fill_parent"
        安卓:layout_height="fill_parent">
        <TabWidget
            安卓:id="@安卓:id/tabs"
            安卓:layout_width="fill_parent"
            安卓:layout_height="wrap_content"/>
        <FrameLayout
            安卓:id="@安卓:id/tabcontent"
            安卓:layout_width="fill_parent"
            安卓:layout_height="fill_parent">
            <TextView 
                安卓:id="@+id/textview1"
                安卓:layout_width="fill_parent"
                安卓:layout_height="fill_parent" 
                安卓:text="year of car" />
            <TextView 
                安卓:id="@+id/textview2"
                安卓:layout_width="fill_parent"
                安卓:layout_height="fill_parent" 
                安卓:text="this is another tab" />
            <TextView 
                安卓:id="@+id/textview3"
                安卓:layout_width="fill_parent"
                安卓:layout_height="fill_parent" 
                安卓:text="this is a third tab" />
            <TextView 
                安卓:id="@+id/textview4"
                安卓:layout_width="fill_parent"
                安卓:layout_height="fill_parent" 
                安卓:text="this is a fourth tab" />
        </FrameLayout>
    </LinearLayout>
</TabHost>

这是我的。java文件:

package com.example.gasfillup;

import 安卓.app.Activity;
import 安卓.app.TabActivity;
import 安卓.os.Bundle;
import 安卓.widget.TabHost;

public class GasFillup extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost mTabHost = getTabHost();

        mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Car Info").setContent(R.id.textview1));
        mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Fillup Info").setContent(R.id.textview2));
        mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Gas Milage").setContent(R.id.textview3));
        mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Stats").setContent(R.id.textview4));       
        mTabHost.setCurrentTab(0);

    }
}

非常感谢您的任何想法或帮助

ironmantis7x


共 (1) 个答案

  1. # 1 楼答案

    用一个。。。所以,framelayout、linearlayout、textview、edittext然后关闭linearlayout

    好吧,让我来编辑一下。。。创建一个单独的XML文件,将所需的整个视图保存在选项卡上,然后使用R.layout进行设置。tab1,而不是将tab1设置为文本视图