09-19-2018, 11:51 PM
برای ایجاد رخداد کلیک برای کلید یا button در Android Studio می توان از کد زیر استفاده کرد:
و کلید ایجاد شده به شرح ذیل می باشد:
کد:
Button Btn2 = (Button)findViewById(R.id.BtnNext);
Btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// کد برای رخداد کلیک در این بخش نوشته می شود
}
});
و کلید ایجاد شده به شرح ذیل می باشد:
کد:
<Button
android:id="@+id/BtnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="صفحه بعدی"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />