• 19.10.2023
  • 398
  • Java buton tıklama olayı basitYazılı Ders

BUTON TIKLAMA OLAYI

Butona metodu bağlayalım

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Selam"
    android:textColor="#000000"
    android:textSize="24sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.685" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="92dp"
    android:onClick="btnClick"
    android:text="Buton Tıklama"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView"
    app:layout_constraintVertical_bias="0.9" />
 
public void btnClick(View view)
{
    String msj="Selam dostlar";

    Toast.makeText(MainActivity.this,msj,Toast.LENGTH_LONG).show();

    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText(msj);
}

 

 

 

 

YORUM YAP