Я пытаюсь вставить текстовое поле для редактирования на вкладку - PullRequest
1 голос
/ 15 марта 2011

Я работаю над проектом 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

Ответы [ 2 ]

1 голос
/ 16 марта 2011

Как сказал Билл Мот, вам нужно обернуть содержимое вкладки в какой-то контейнер. Вот пример использования простого 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));
....

Реально, именно так вы должны делать все вкладки (чтобы вы могли иметь больше, чем просто текст), но вы поняли идею.

1 голос
/ 16 марта 2011

Оберните ваш ... так: framelayout, linearlayout, textview, edittext, а затем закройте linearlayout.

Хорошо, позвольте мне отредактировать это ... создайте отдельный файл XML, чтобы сохранить весь вид, который выхотите на вкладке, а затем установите его с помощью R.layout.tab1 вместо установки tab1 для просмотра текста.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...