Java ReactNative:通过NativeBridge代码中的findViewById获取元素

Java ReactNative:通过NativeBridge代码中的findViewById获取元素,java,react-native,react-native-android,Java,React Native,React Native Android,是否可以通过本机Java代码从React Native视图获取元素 例如,这是我在app.js中代码的一部分: <View style={styles.imageContainer}> <Image id="bitmapPreview"/> </View> 我找不到答案:(您可以使用android方法在drawable上获取imageId。您可以检查:好的,现在我有:iv=(ImageView)context.getCurrentActivity().

是否可以通过本机Java代码从React Native视图获取元素

例如,这是我在
app.js
中代码的一部分:

<View style={styles.imageContainer}>
   <Image id="bitmapPreview"/>
</View>
我找不到答案:(

您可以使用android方法在drawable上获取imageId。您可以检查:好的,现在我有:iv=(ImageView)context.getCurrentActivity().getResources().getIdentifier(“bitmapPreview”,“drawable”,context.getPackageName());不起作用。我得到:错误:不兼容的类型:int无法转换为ImageViewgetIdentifier()返回int类型,这是图像的ID。您应该编写:int-imageId=context.getCurrentActivity().getResources().getIdentifier(“bitmapPreview”,“drawable”,context.getPackageName());iv=(ImageView)context.getCurrentActivity().findViewById(imageId);(我还没有测试)这可能解决了我的问题:你可以使用android方法在drawable上获取imageId。你可以检查:好的,现在我有:iv=(ImageView)context.getCurrentActivity().getResources().getIdentifier(“bitmapPreview”,“drawable”,context.getPackageName());不起作用。我得到:错误:不兼容的类型:int无法转换为ImageViewgetIdentifier()返回int类型,这是图像的ID。您应该编写:int-imageId=context.getCurrentActivity().getResources().getIdentifier(“bitmapPreview”,“drawable”,context.getPackageName());iv=(ImageView)context.getCurrentActivity().findviewbyd(imageId);(我还没有测试)可能解决了我的问题:D
iv = (ImageView) context.getCurrentActivity().findViewById(R.id.bitmapPreview);