我想从底部导航视图中从所选项目(在这种情况下,它是 R.id.status )中选择图像,并在名为 statusList 的回收视图中显示图像。如果不推荐使用 startActivityForResult,我该怎么做?
首先你需要申报
private ActivityResultLauncher<String> imagePickerLauncher;
之后是启动图像选择器的方式
// Launch the image picker
imagePickerLauncher.launch("image/*");
要检索结果,请复制此代码
// Initialize the imagePickerLauncher
imagePickerLauncher = registerForActivityResult(new
ActivityResultContracts.GetContent(), uri -> {
if (uri != null) {
// Do something with the selected image URI
// For example, add it to the RecyclerView adapter
}
});