2011-03-15 64 views
1

我正在一個android項目,我有我的四個選項卡。在其中一個選項卡上,我試圖插入一個編輯字段框。有關如何做到這一點的線索?我想插入一個編輯文本框到一個標籤

這裏是我的main.xml文件:

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

,這裏是我的java文件:

package com.example.gasfillup; 

import android.app.Activity; 
import android.app.TabActivity; 
import android.os.Bundle; 
import android.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

+0

那麼,你想獲得一個編輯框*上的卡*,或選項卡的內容之內? – riwalk 2011-03-15 20:44:24

+0

內的選項卡...對不起,我應該更清楚。 @ Stargazer712 – ironmantis7x 2011-03-15 21:23:11

回答

1

了......所以,FrameLayout裏,LinearLayout中,TextView的,EditText上然後關閉的LinearLayout包裝你。

好,讓我編輯......創建一個單獨的XML文件來保存你想要的選項卡上的整個視圖,然後用R.layout.tab1設置,而不是設置TAB1到TextView的。

+0

不理解你的回覆。你可以給我一個例子嗎?? – ironmantis7x 2011-03-15 21:36:08

+0

工作!我將在Java中閱讀更多關於容器的知識,並嘗試更多的東西! – ironmantis7x 2011-03-16 22:09:35

+0

顯示一些愛的人。扔我upvote和複選標記;)它有助於我的聲譽,並顯示其他人,你會承認他們的幫助。 – 2011-03-17 00:28:42

1

正如比爾·莫特說,你需要某種容器內包裹標籤的內容。下面是一個使用簡單的LinearLayout一個例子:

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

然後改變背後代碼:

.... 
mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Stats").setContent(R.id.panel4)); 
.... 

實際上,這是你應該怎麼做所有選項卡(這樣就可以擁有多隻文字),但你明白了。

+0

謝謝!!!我會試一下!! – ironmantis7x 2011-03-16 02:16:51

+0

行 - 我必須我是個白癡......我試圖複製相同結構的其他選項卡並沒有在模擬器的工作...我在做什麼錯? – ironmantis7x 2011-03-17 03:14:34

+0

你能幫我一下嗎?我是Java和Android和XML的新手。 – ironmantis7x 2011-03-17 03:16:01

相關問題