jeudi 8 septembre 2022

How to insert text from textview according to checkbox?

I am making shopping list app in Kotlin. Main screen has 4 tabs, each for one store. On page for inserting new items I have 2 textview's, for product name and quantity. Also, on that page I have 4 checkboxes for 4 stores. I want to insert texts from textviews on specific tab when checkbox with same name as tab is checked. Didn't find any examples online. I would much appreciate everyones help.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="30sp"
        tools:context=".ItemInputActivity" >

    <EditText
            android:id="@+id/productId"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:visibility="gone"
            tools:ignore="MissingConstraints"
    />

    <EditText
            android:id="@+id/inputItem"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_marginStart="22dp"
            android:layout_marginTop="26dp"
            android:layout_marginEnd="22dp"
            android:ems="10"
            android:hint="@string/naziv_proizvoda"
            android:background="@drawable/bg_form"
            android:paddingStart="10dp"
            android:paddingEnd="10dp"
            android:inputType="textPersonName"
            android:textSize="16sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:importantForAutofill="no" />

    <EditText
        android:id="@+id/inputNumber"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_marginStart="22dp"
        android:layout_marginTop="20sp"
        android:layout_marginEnd="22dp"
        android:background="@drawable/bg_form"
        android:ems="10"
        android:hint="@string/kolicina_proizvoda"
        android:importantForAutofill="no"
        android:inputType="number"
        android:paddingStart="10dp"
        android:paddingEnd="10dp"
        android:textSize="16sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/inputItem" />

    <CheckBox
        android:id="@+id/konzumCheck"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="22sp"
        android:layout_marginEnd="22sp"
        android:minHeight="48dp"
        android:text="@string/konzum"
        app:layout_constraintBottom_toTopOf="@+id/lidlCheck"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/inputNumber" />

    <CheckBox
            android:id="@+id/lidlCheck"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="22sp"
            android:layout_marginEnd="22sp"
            android:text="@string/lidl"
            android:minHeight="48dp"
            app:layout_constraintTop_toBottomOf="@id/konzumCheck"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/kauflandCheck"

    />

    <CheckBox
            android:id="@+id/kauflandCheck"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="22sp"
            android:layout_marginEnd="22sp"
            android:text="@string/kaufland"
            android:minHeight="48dp"
            app:layout_constraintTop_toBottomOf="@id/lidlCheck"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/sparCheck"

    />

    <CheckBox
            android:id="@+id/sparCheck"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="22sp"
            android:layout_marginEnd="22sp"
            android:text="@string/spar"
            android:minHeight="48dp"
            app:layout_constraintTop_toBottomOf="@id/kauflandCheck"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/inputButton"

    />

    <Button
        android:id="@+id/inputButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="35sp"
        android:text="@string/spremi"
        android:textSize="12sp"
        app:layout_constraintEnd_toStartOf="@id/itemListActivity"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/sparCheck" />

    <Button
        android:id="@+id/itemListActivity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="35sp"
        android:text="@string/lista_proizvoda"
        android:textSize="12sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/inputButton"
        app:layout_constraintTop_toBottomOf="@id/sparCheck"

        />

</androidx.constraintlayout.widget.ConstraintLayout>



Aucun commentaire:

Enregistrer un commentaire