Alex Kamau
Alex Kamau

Reputation: 39

How to Create interrelated items in xml file android

I have created a couple of questions for my android app, question two depends on one, i want to create it that if you fill that zero persons were tested it will automatically fill the next segment of the question.Am stranded, how do i do it? here is my 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>

i also want to group them in that when a section automatically fills itself the user is immediately brought to the next section. e.g When he/she fill in "how many people tested" female 0 and male 0 the next segment up to how many contacts automatically fills to 0. `

Upvotes: 0

Views: 77

Answers (1)

Sina Khorshidian
Sina Khorshidian

Reputation: 332

You can use interface. if so, you should first set addTextChangedListener() in your desired edittext, then set interface in one of the addTextChangedListener() method.

example:

first define interface

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

then

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());
            }
        });

you can use mInterface.onEditTextAction(s.toString()); in each text change listener methode you like. it passes the text entered in edittext to interface for further use. then in your activity

mInterface myInterface = (mInterface) mContext;

and at last use

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

and change whatever you want.

Upvotes: 1

Related Questions