Reputation: 68
I have this code:
final byte[] bslval = data1.getByteArray(HRPService.BSL_VALUE);
runOnUiThread(new Runnable()
{
public void run()
{
if (bslval != null)
{
try
{
Log.i(TAG, "BYTE BSL VAL =" + bslval[0]);
//TextView bsltv = (TextView) findViewById(R.id.BodySensorLocation);
EditText bsltv = (EditText) findViewById(R.id.EditSensorLocation);
String bslstr = new String(bslval, "UTF-8");
bsltv.setText(bslstr);
}
catch (Exception e)
{
Log.e(TAG, e.toString());
}
The EditText does show the value as a "d" but not as "64" (which I want). How do I convert this to a decimal instead?
Upvotes: 0
Views: 857
Reputation: 43798
Something like this:
String bslstr = String.valueOf(bslval[0] & 0xff);
This assumes, the value is actually in bslval[0]
. The & 0xff
is there to get positive results for byte values between (byte)0x80
and (byte)0xff
.
Upvotes: 2
Reputation: 51721
Use the simpler string concatenation if you only want to set the first byte value bslval[0]
as text.
bsltv.setText(bslval[0] + "");
Upvotes: 0