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

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

Can I convert sparse array into string?

问题

我正在开发一个二维码扫描应用程序我正在使用条码检测器Barcode Detector来读取二维码并且结果存储在 SparseArray<Barcode>所以我的问题是我能够将 SparseArray<Barcode> 转换为字符串吗这样我就可以使用分割Split函数来拆分字符串然后与另一个字符串进行比较

@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);
            }
        });
    }
}
英文:

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.

@Override
        public void receiveDetections(Detector.Detections&lt;Barcode&gt; detections) {
            final SparseArray&lt;Barcode&gt; 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);


                    }
                });
            }

        }

答案1

得分: 1

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

class b&lt;T&gt; : SparseArray&lt;T&gt;(){

    @Override
    public String toString() {
      return //自定义的字符串;
 }
}

完成后,您可以调用 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:

class b&lt;T&gt; : SparseArray&lt;T&gt;(){

    @Override
    public String toString() {
      return //customised String;
 }
}

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:

确定