如何在 xml 文件 android 中创建相互关联的项目

How to Create interrelated items in xml file android

我为我的 android 应用程序创建了几个问题,问题二取决于一个问题,我想创建一个如果你填写零人测试它会自动填写下一部分question.Am 搁浅了,我该怎么办?这是我的 XML

    `<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".GeneratorActivity">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <!--Put form controls here-->

        </LinearLayout>
    </ScrollView>


    <TextView
        android:id="@+id/tested1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many people tested"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/txtMale11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />

        <EditText
            android:id="@+id/male11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue" />

</LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


<TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Female"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="209dp" />

        <EditText
            android:id="@+id/female11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue" />

    </LinearLayout>

    <TextView
        android:id="@+id/positive1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many people positive"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />

        <EditText
            android:id="@+id/male12"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textView10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />

        <EditText
            android:id="@+id/female12"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue" />

    </LinearLayout>

    <TextView
        android:id="@+id/linked1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many people linked"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />

        <EditText
            android:id="@+id/male13"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textView19"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />

        <EditText
            android:id="@+id/female13"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue" />

    </LinearLayout>
    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many people started ART"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />
        <EditText
            android:id="@+id/editText6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textView14"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />
        <EditText
            android:id="@+id/editText11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <TextView
        android:id="@+id/textView533"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many contacts"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView443"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />
        <EditText
            android:id="@+id/editText96"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textView83"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />
        <EditText
            android:id="@+id/editText89"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <TextView
        android:id="@+id/textView53333"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many tested"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView464343"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />
        <EditText
            android:id="@+id/editText5796"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textView833"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />
        <EditText
            android:id="@+id/editText579"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <TextView
        android:id="@+id/textViewdvssd533"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many people positive"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textViedvdsw443w443"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />
        <EditText
            android:id="@+id/editTextdvd9696"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textVdhddvv83v83"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />
        <EditText
            android:id="@+id/editTedjsb"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>

    <TextView
        android:id="@+id/textVidvdn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many linked"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textViedjhvb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />
        <EditText
            android:id="@+id/editTedjhvb"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textVdjbv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />
        <EditText
            android:id="@+id/editTedub"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <TextView
        android:id="@+id/textViedjjd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many started ART"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textVidjvj"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />
        <EditText
            android:id="@+id/editTexdjbv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textVdmjb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />
        <EditText
            android:id="@+id/editTjdhbdsk"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <TextView
        android:id="@+id/textVjfbjd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How many contacts"
        android:textAppearance="@android:style/TextAppearance.Large"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="16dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textVrjgr"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="63dp" />
        <EditText
            android:id="@+id/editTdnj"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/textVitih"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"
            android:textAppearance="@android:style/TextAppearance.Large"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="209dp" />
        <EditText
            android:id="@+id/edittu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:textColor="@color/blue"
            />

    </LinearLayout>


</LinearLayout>

我还想对它们进行分组,当一个部分自动填充时,用户会立即被带到下一个部分。例如 当he/she填写"how many people tested"女0和男0时下段最多有多少个联系人自动补0。 `

可以使用界面。如果是这样,您应该首先在所需的编辑文本中设置 addTextChangedListener(),然后在 addTextChangedListener() 方法之一中设置界面。

示例:

先定义接口

public interface mInterface {
    void onEditTextAction(String key);
}

然后

mEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                  mInterface.onEditTextAction(s.toString());
            }
        });

您可以在每个您喜欢的文本更改侦听器方法中使用 mInterface.onEditTextAction(s.toString());。它将在 edittext 中输入的文本传递给界面以供进一步使用。 然后在你的 activity

mInterface myInterface = (mInterface) mContext;

最后使用

new  mInterface() {
    @Override
    public void onEditTextAction(String key) {
        // use edittext string here
    }
};

随心所欲地改变。