How do I pass entries from xml to kt?

  android, kotlin

I volunteer with an organization that provides no-cost labor to build wheelchair ramps, wrapiowa.org
One of our volunteers did an app for Apple phones to assist in this activity. I am attempting to duplicate his work for Android using Android Studio but need help. My expertise is in wood designing and construction, not app programming.

Thanks, Ron

Here is what I have, two user inputs for length in inches and 16th’s and height in inches and 16th’s.

Input variables: edittext_number_length, edittext_number16_length, edittext_number_height, edittext_number16_height

The output I want is an angle in degrees and a run length:

Output variables: textView_cut_angle, textView_run

Based on this math:

Math:
length = edittext_number_length + (edittext_number16_length/16)
height = edittext_number_height + (edittext_number16_height/16)
textView_cut_angle = (asin(height/lenght)*180/3.1416)
textView_run = (sqrt(pow(length, 2) - pow(height,2)))

angle.kt


    package com.example.wrap_iowarampdesignaid

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity

class angle : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_angle)

    }
    fun launchAngleActivity(view: View) {
        startActivity(Intent([email protected],illustration::class.java))
    }
    fun launchUpdateActivity(view: View) {

    }
}

activity_angle.xml


    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@android:color/black"
    tools:context=".angle">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="218dp"
        android:layout_height="100dp"
        android:layout_marginTop="16dp"
        android:contentDescription="@string/logo"
        android:scaleType="centerInside"
        android:src="@drawable/logo"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/string2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:text="@string/angle2"
        android:textColor="@android:color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/logo" />

    <Button
        android:id="@+id/angle_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="launchAngleActivity"
        android:text="@string/s_illustration"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        app:backgroundTint="#2196F3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:id="@+id/update_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:onClick="launchUpdateActivity"
        android:text="@string/Update"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        app:backgroundTint="#2196F3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView18" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:text="@string/s_length"
        android:textColor="@android:color/white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/string2" />

    <TextView
        android:id="@+id/textView18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:text="@string/s_heigth"
        android:textColor="@android:color/white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView7" />

    <TextView
        android:id="@+id/textView19"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:text="@string/sc_angle"
        android:textColor="@android:color/white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/update_button" />

    <TextView
        android:id="@+id/textView20"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:text="@string/sc_length"
        android:textColor="@android:color/white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView19" />

    <TextView
        android:id="@+id/textView21"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:text="@string/degrees"
        android:textColor="@android:color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/textView19" />

    <TextView
        android:id="@+id/textView22"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:text="@string/inches"
        android:textColor="@android:color/white"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/textView20" />

    <EditText
        android:id="@+id/edittext_number_length"
        android:layout_width="40dp"
        android:layout_height="0dp"
        android:layout_marginEnd="16dp"
        android:background="@color/white"
        android:inputType="number"
        app:layout_constraintBottom_toBottomOf="@+id/textView7"
        app:layout_constraintEnd_toStartOf="@+id/edittext_number16_length"
        app:layout_constraintTop_toTopOf="@+id/textView7" />

    <EditText
        android:id="@+id/edittext_number16_length"
        android:layout_width="25dp"
        android:layout_height="0dp"
        android:background="@color/white"
        android:inputType="number"
        app:layout_constraintBottom_toBottomOf="@+id/textView7"
        app:layout_constraintEnd_toStartOf="@+id/textView_number_length"
        app:layout_constraintTop_toTopOf="@+id/textView7" />

    <EditText
        android:id="@+id/edittext_number_height"
        android:layout_width="40dp"
        android:layout_height="0dp"
        android:layout_marginEnd="16dp"
        android:background="@color/white"
        android:inputType="number"
        app:layout_constraintBottom_toBottomOf="@+id/textView18"
        app:layout_constraintEnd_toStartOf="@+id/edittext_number16_height"
        app:layout_constraintTop_toTopOf="@+id/textView18" />

    <EditText
        android:id="@+id/edittext_number16_height"
        android:layout_width="25dp"
        android:layout_height="0dp"
        android:background="@color/white"
        android:inputType="number"
        app:layout_constraintBottom_toBottomOf="@+id/textView18"
        app:layout_constraintEnd_toStartOf="@+id/textView_number16_length"
        app:layout_constraintTop_toTopOf="@+id/textView18"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@+id/textView_number_length"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:background="@color/white"
        android:text="@string/_16"
        app:layout_constraintBottom_toBottomOf="@+id/textView7"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/textView7" />

    <TextView
        android:id="@+id/textView_number16_length"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:background="@color/white"
        android:text="@string/_16"
        app:layout_constraintBottom_toBottomOf="@+id/textView18"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/textView18" />

    <TextView
        android:id="@+id/textView_cut_angle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:background="@color/white"
        android:text="0"
        app:layout_constraintBottom_toBottomOf="@+id/textView19"
        app:layout_constraintEnd_toStartOf="@+id/textView21"
        app:layout_constraintTop_toTopOf="@+id/textView19" />

    <TextView
        android:id="@+id/textView_run"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:background="@color/white"
        android:text="0"
        app:layout_constraintBottom_toBottomOf="@+id/textView20"
        app:layout_constraintEnd_toStartOf="@+id/textView22"
        app:layout_constraintTop_toTopOf="@+id/textView20" />

</androidx.constraintlayout.widget.ConstraintLayout>

Source: Android Questions

LEAVE A COMMENT