如何使用kotlin在另一页的文本视图中显示toast.maketext
//这是我使用kotlin覆盖的扫描仪条形码代码
fun接收访问(检测:detector..detections){
val barcodes = detections.detectedItems
if (barcodes.size() == 1) {
scannedValue = barcodes.valueAt(0).rawValue
runOnUiThread {
cameraSource.stop()
Toast.makeText(this@InsertStockInActivity, "value- $scannedValue", Toast.LENGTH_SHORT).show()
finish()
}
}else
{
Toast.makeText(this@InsertStockInActivity, "value- else", Toast.LENGTH_SHORT).show()
}
}
//这是我的输入页面
覆盖fun increateview(fordater:layoutinflater,container,container:viewgroup? {
binding = FragmentInputStockInBinding.inflate(inflater, container, false)
binding.btnScanBarcode.setOnClickListener{ nav.navigate(R.id.insertStockInActivity)}
return binding.root
}[enter image description here][1]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想您应该将吐司文本提取为变量,然后将其传递到另一页(我认为您的均值是另一个片段/活动或另一个屏幕)
,然后通过
toastText 传递到另一个页面>意图或
Safe-args
如果您使用的是JetPack Navigationi thnk you should extract your toast text as a variable and pass it to another page ( i assume that your mean are to another fragment/activity or to another screen)
and pass
toastText
to another page viaIntent
orsafe-args
if you are using Jetpack Navigation您可以使用视图模型,实时数据或另一个(静态)对象将结果保存在变量中。按照相同的行,您可以在另一个类中创建一个show吐司功能,只需传递您所处的片段或活动的上下文即可。
You could use a view model, live data, or another (static) object to hold your results in a variable. Along the same lines, you can create a show toast function in another class and just pass the context of the fragment or activity that you are in. For example a fragment context could be requireContext().