Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java TextView::getText()对于不可见的字符返回-3_Java_Android_String_Byte_Ascii - Fatal编程技术网

Java TextView::getText()对于不可见的字符返回-3

Java TextView::getText()对于不可见的字符返回-3,java,android,string,byte,ascii,Java,Android,String,Byte,Ascii,如果我按如下方式设置TextView字节: byte[] byteArray = { 25, 20, -101 }; TextView encrypted_text = (TextView) findViewById(R.id.encrypted); encrypted_text.setText(new String(byteArray)); 然后我可以返回25,20,但不是-101值。 对于第三个字符,我总是得到-3作为输出: Log.v(TAG, "3rd byte: "+ (byte)

如果我按如下方式设置TextView字节:

byte[] byteArray = { 25, 20, -101 };
TextView encrypted_text = (TextView) findViewById(R.id.encrypted);
encrypted_text.setText(new String(byteArray));
然后我可以返回25,20,但不是-101值。 对于第三个字符,我总是得到-3作为输出:

Log.v(TAG, "3rd byte: "+ (byte) encrypted_text.getText().toString().charAt(2));
实际上,对于所有不可见的字符,都返回p.S.-3


如何从TextView获取字节数组?

我知道如何在TextView中存储和检索负字节值。 首先,我们需要将有符号字节转换为无符号字节。因为在Java中,所有类型都经过签名,所以我们需要手动执行此操作:

// remove signed bit(32nd), keep value as "next" (127+...) positive byte value
int unsignedValue = 255 - ((int)byteArray[i])&0b1111111;