可以将稀疏数组转换为字符串吗?

huangapple go评论144阅读模式
英文:

Can I convert sparse array into string?

问题

  1. 我正在开发一个二维码扫描应用程序我正在使用条码检测器Barcode Detector来读取二维码并且结果存储在 SparseArray<Barcode> 所以我的问题是我能够将 SparseArray<Barcode> 转换为字符串吗这样我就可以使用分割Split函数来拆分字符串然后与另一个字符串进行比较
  2. @Override
  3. public void receiveDetections(Detector.Detections<Barcode> detections) {
  4. final SparseArray<Barcode> qrcodes = detections.getDetectedItems();
  5. if (qrcodes.size() != 0) {
  6. txtResult.post(new Runnable() {
  7. @Override
  8. public void run() {
  9. Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
  10. vibrator.vibrate(100);
  11. txtResult.setText(qrcodes.valueAt(0).displayValue);
  12. }
  13. });
  14. }
  15. }
英文:

I'm working on QR code scanning app. I'm using Barcode Detector to read QR code and the result is storing in SparseArray<Barcode>. So my question is can I convert SparseArray<Barcode> into String? So that I can break the string using Split function and later compare it with another String.

  1. @Override
  2. public void receiveDetections(Detector.Detections&lt;Barcode&gt; detections) {
  3. final SparseArray&lt;Barcode&gt; qrcodes = detections.getDetectedItems();
  4. if (qrcodes.size() != 0) {
  5. txtResult.post(new Runnable() {
  6. @Override
  7. public void run() {
  8. Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
  9. vibrator.vibrate(100);
  10. txtResult.setText(qrcodes.valueAt(0).displayValue);
  11. }
  12. });
  13. }
  14. }

答案1

得分: 1

只需使用 toString() 方法,如下所示: SparseArray&lt;Int&gt;().toString()
如果您正在处理内置类(库类),可以扩展该类以自定义所需的任何行为,例如:

  1. class b&lt;T&gt; : SparseArray&lt;T&gt;(){
  2. @Override
  3. public String toString() {
  4. return //自定义的字符串;
  5. }
  6. }

完成后,您可以调用 SparseArray&lt;Int&gt;().toString() 来获取自定义的字符串表示。

英文:

Siimply You can use toString() method like: SparseArray&lt;Int&gt;().toString().
If you are dealing with Built-in class( library classes ), Extend that class to customize any behavior you want, For Example:

  1. class b&lt;T&gt; : SparseArray&lt;T&gt;(){
  2. @Override
  3. public String toString() {
  4. return //customised String;
  5. }
  6. }

After this you can call SparseArray&lt;Int&gt;().toString() to get your customize String representation.

huangapple
  • 本文由 发表于 2020年10月9日 02:25:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/64268562.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定