Я только начал изучать Kotlin и решил написать очень простую c программу. Предполагается, что это конвертер валют, но сейчас я просто хочу выдать число, которое я ввожу в "editTextEingabe" ("Eingabe" = немецкий для ввода), в textView "textViewAusgabe". Я приведу свой код ниже и буду очень рад, если кто-нибудь сможет мне помочь Спасибо!
PS: «editTextEingabe» настроен так, чтобы разрешать ввод только цифр и десятичных знаков, но я не знаю, изменит ли это что-либо.
Обновление 2: Проблема в том, что десятичное число, которое я печатаю в editTextEingabe, не появляется в textViewAusgabe после того, как In нажимает кнопку ButtonBerechnen. Более просто: я хочу выдать текст (здесь: число), который я только что ввел в editText в виджет textView, но это не работает.
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var eingabe = findViewById<EditText>(R.id.editTextEingabe)
var eingabeString: String = eingabe.toString()
var ergebnis: String
val buttonBerechnen: Button = findViewById(R.id.buttonBerechnen)
buttonBerechnen.setOnClickListener() {
ergebnis = eingabeString
textViewAusgabe.text = ("$ergebnis")
}
}
}
Обновление: вот мой XML , если это поможет:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textViewAusgabe"
android:layout_width="108dp"
android:layout_height="46dp"
android:layout_marginTop="228dp"
android:background="#4600BCD4"
android:textAlignment="center"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextEingabe"
android:layout_width="121dp"
android:layout_height="46dp"
android:layout_marginStart="64dp"
android:layout_marginTop="228dp"
android:background="#4600BCD4"
android:ems="10"
android:hint="$ eingeben"
android:inputType="number|numberDecimal"
android:numeric="integer|decimal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="43dp"
android:layout_height="30dp"
android:layout_marginTop="236dp"
android:text="$ = "
android:textAlignment="center"
android:textSize="22sp"
app:layout_constraintStart_toEndOf="@+id/editTextEingabe"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView4"
android:layout_width="57dp"
android:layout_height="27dp"
android:layout_marginTop="236dp"
android:layout_marginEnd="36dp"
android:text="€"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/textViewAusgabe"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/buttonBerechnen"
android:layout_width="116dp"
android:layout_height="69dp"
android:layout_marginStart="144dp"
android:layout_marginBottom="188dp"
android:background="#4600BCD4"
android:text="Berechnen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>```