java - 我可以将稀疏数组转换为字符串吗?
问题描述
我正在开发 QR 码扫描应用程序。我正在使用 Barcode Detector 读取 QR 码,结果存储在 SparseArray 中。所以我的问题是我可以将 SparseArray 转换为 String 吗?这样我就可以使用拆分函数打破字符串,然后将其与另一个字符串进行比较。
@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrcodes = detections.getDetectedItems();
if (qrcodes.size() != 0) {
txtResult.post(new Runnable() {
@Override
public void run() {
Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(100);
txtResult.setText(qrcodes.valueAt(0).displayValue);
}
});
}
}
解决方案
您可以使用toString()
以下方法:SparseArray<Int>().toString()
. 如果您正在处理内置类(库类),请扩展该类以自定义您想要的任何行为,例如:
class b<T> : SparseArray<T>(){
@Override
public String toString() {
return //customised String;
}
}
在此之后,您可以调用SparseArray<Int>().toString()
以获取您的自定义字符串表示。
推荐阅读
- sql-server - 将数据分组为模糊的间隙和孤岛
- swift - UIView 内的自定义视图的触摸检测问题而不是 UIScrollView
- php - 在本地访问我的 dockerized Laravel 应用程序
- python - python中按日期的线性回归预测
- amazon-web-services - 如何触发和处理 AWS MediaLive 上的流中断?
- python - 当 Python 和 Oracle 都是 64 位时,为什么 cx_Oracle 会给出不正确的架构错误?
- php - 无法使用 php datetime 方法转换为 12 小时制
- java - 如何检查“?” 类对象实例的 SomeInterface
- jquery - 使用 jQuery 悬停列表项时从 img 更改图像
- c# - Automapper - 将复杂对象列表映射到属性列表