From e2b43e2a2dae7078efa72936f8845d3c6d8b7e02 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Sun, 26 Oct 2025 16:44:50 +0100 Subject: [PATCH] CheckBox: fix setText() with non-String CharSequence --- .../generated_headers/android_widget_CheckBox.h | 8 ++++---- src/api-impl-jni/widgets/android_widget_CheckBox.c | 4 ++-- src/api-impl/android/widget/Button.java | 2 +- src/api-impl/android/widget/CheckBox.java | 6 +++++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/api-impl-jni/generated_headers/android_widget_CheckBox.h b/src/api-impl-jni/generated_headers/android_widget_CheckBox.h index 665b36a8..4b307432 100644 --- a/src/api-impl-jni/generated_headers/android_widget_CheckBox.h +++ b/src/api-impl-jni/generated_headers/android_widget_CheckBox.h @@ -233,11 +233,11 @@ JNIEXPORT jboolean JNICALL Java_android_widget_CheckBox_isChecked /* * Class: android_widget_CheckBox - * Method: setText - * Signature: (Ljava/lang/CharSequence;)V + * Method: native_setText + * Signature: (JLjava/lang/String;)V */ -JNIEXPORT void JNICALL Java_android_widget_CheckBox_setText - (JNIEnv *, jobject, jobject); +JNIEXPORT void JNICALL Java_android_widget_CheckBox_native_1setText + (JNIEnv *, jobject, jlong, jstring); #ifdef __cplusplus } diff --git a/src/api-impl-jni/widgets/android_widget_CheckBox.c b/src/api-impl-jni/widgets/android_widget_CheckBox.c index 1cf67165..0c74cb40 100644 --- a/src/api-impl-jni/widgets/android_widget_CheckBox.c +++ b/src/api-impl-jni/widgets/android_widget_CheckBox.c @@ -46,9 +46,9 @@ JNIEXPORT void JNICALL Java_android_widget_CheckBox_setOnCheckedChangeListener(J } } -JNIEXPORT void JNICALL Java_android_widget_CheckBox_setText(JNIEnv *env, jobject this, jstring text) +JNIEXPORT void JNICALL Java_android_widget_CheckBox_native_1setText(JNIEnv *env, jobject this, jlong widget_ptr, jstring text) { - GtkCheckButton *button = GTK_CHECK_BUTTON(_PTR(_GET_LONG_FIELD(this, "widget"))); + GtkCheckButton *button = GTK_CHECK_BUTTON(_PTR(widget_ptr)); if (text == NULL) { gtk_check_button_set_label(button, NULL); return; diff --git a/src/api-impl/android/widget/Button.java b/src/api-impl/android/widget/Button.java index 9c276b67..8b3a85ed 100644 --- a/src/api-impl/android/widget/Button.java +++ b/src/api-impl/android/widget/Button.java @@ -37,7 +37,7 @@ public class Button extends TextView { @Override protected native long native_constructor(Context context, AttributeSet attrs); - public native final void native_setText(long widget, String text); + public native void native_setText(long widget, String text); @Override protected native void nativeSetOnClickListener(long widget); protected native void native_setCompoundDrawables(long widget, long paintable); diff --git a/src/api-impl/android/widget/CheckBox.java b/src/api-impl/android/widget/CheckBox.java index ce099193..5a2ae98c 100644 --- a/src/api-impl/android/widget/CheckBox.java +++ b/src/api-impl/android/widget/CheckBox.java @@ -28,7 +28,9 @@ public class CheckBox extends CompoundButton { public native boolean isChecked(); @Override - public native void setText(CharSequence text); + public void setText(CharSequence text) { + native_setText(widget, text == null ? "" : text.toString()); + } // following methods are overridden to prevent calling incompatible methods from superclasses @Override @@ -38,4 +40,6 @@ public class CheckBox extends CompoundButton { @Override public void setTextSize(float size) {} + @Override + public native void native_setText(long widget, String text); }