CheckBox: fix setText() with non-String CharSequence

This commit is contained in:
Julian Winkler
2025-10-26 16:44:50 +01:00
parent a861a62107
commit e2b43e2a2d
4 changed files with 12 additions and 8 deletions

View File

@@ -233,11 +233,11 @@ JNIEXPORT jboolean JNICALL Java_android_widget_CheckBox_isChecked
/* /*
* Class: android_widget_CheckBox * Class: android_widget_CheckBox
* Method: setText * Method: native_setText
* Signature: (Ljava/lang/CharSequence;)V * Signature: (JLjava/lang/String;)V
*/ */
JNIEXPORT void JNICALL Java_android_widget_CheckBox_setText JNIEXPORT void JNICALL Java_android_widget_CheckBox_native_1setText
(JNIEnv *, jobject, jobject); (JNIEnv *, jobject, jlong, jstring);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -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) { if (text == NULL) {
gtk_check_button_set_label(button, NULL); gtk_check_button_set_label(button, NULL);
return; return;

View File

@@ -37,7 +37,7 @@ public class Button extends TextView {
@Override @Override
protected native long native_constructor(Context context, AttributeSet attrs); 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 @Override
protected native void nativeSetOnClickListener(long widget); protected native void nativeSetOnClickListener(long widget);
protected native void native_setCompoundDrawables(long widget, long paintable); protected native void native_setCompoundDrawables(long widget, long paintable);

View File

@@ -28,7 +28,9 @@ public class CheckBox extends CompoundButton {
public native boolean isChecked(); public native boolean isChecked();
@Override @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 // following methods are overridden to prevent calling incompatible methods from superclasses
@Override @Override
@@ -38,4 +40,6 @@ public class CheckBox extends CompoundButton {
@Override @Override
public void setTextSize(float size) {} public void setTextSize(float size) {}
@Override
public native void native_setText(long widget, String text);
} }