I have MainActivity where I declare editTextValue as ObservableField
I want to get it with editTextValue.get() on button click and pass it to another function. But I am always getting empty.
class MainActivity : AppCompatActivity() {
var editTextValue = ObservableField<String>("")
if(editTextValue.get()!!.isEmpty()){
println("WHY IS ITNULL")
return@setOnClickListener
}
}
and In my xml layout I have defined a variable activity and set the text of editText as,
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="activity"
type="com.example.ashishgpt.MainActivity" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1C1B1F"
tools:context=".MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="409dp"
android:layout_height="wrap_content"
android:background="#333333"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="AshishGpt"
app:titleTextColor="#FFFFFF" />
<EditText
android:id="@+id/editTextText"
android:layout_width="364dp"
android:layout_height="53dp"
android:layout_marginStart="1dp"
android:layout_marginEnd="3dp"
android:layout_marginBottom="2dp"
android:background="#333333"
android:ems="10"
android:hint="Enter your prompt here"
android:text="@={activity.editTextValue}"
android:inputType="text"
android:paddingStart="10dp"
android:textColor="#FBFBFB"
android:textColorHint="#D1CACA"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/imageButton"
app:layout_constraintStart_toStartOf="parent" />
No matter what I type in textenter code herefield, it prints empty on button click.
Is there a point I am missing?