Hello fellow programmers!
i try to call element from my xml file example : a " Button " from my activity.xml but the MainActivity.kt do not resolve my id when i try to call it inside the code i tried to clean and re-build the project but still have the problem also invalidate caches restart
like this i want to call a the button from my acitivty_main.xml
button.setOnClickListener{ }
MainActivity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.mostafa.stringlength.R.id.editText
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.(i here try to call the button) but shows me nothing //
}
}
xml acitivty :
<?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"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="138dp"
android:layout_height="58dp"
android:layout_marginStart="136dp"
android:layout_marginEnd="137dp"
android:layout_marginBottom="212dp"
android:text="أظهار النتيجة"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/editText"
android:layout_width="411dp"
android:layout_height="360dp"
android:layout_marginStart="43dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="43dp"
android:ems="10"
android:inputType="textPersonName"
android:text="ادخل النص هنا"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="417dp"
android:layout_height="195dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/result"
android:text="النتائج:"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>