[SOLVED] How i change the data from ubidots to a whole number

Hello i already use all the tutorials but when i read the data from ubidots, i have “com.ubidots.Value@88fdb4b” and i want the exactly number i dont know how to put that on whole numer the code is showed below, can you please help me?

public class MainActivity extends Activity {





    TextView textElement;


    private static final String BATTERY_LEVEL = "level";
    private TextView mBatteryLevel;
    private TextView traer;
    private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int level = intent.getIntExtra(BATTERY_LEVEL, 0);

            mBatteryLevel.setText(Integer.toString(level) + "%");
            new ApiUbidots().execute(level);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mBatteryLevel = (TextView) findViewById(R.id.batteryLevel);
        traer = (TextView) findViewById(dato);
    }

    @Override
    protected void onStart() {
        super.onStart();
        registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    }

    @Override
    protected void onStop() {
        unregisterReceiver(mBatteryReceiver);
        super.onStop();
    }

    public class ApiUbidots extends  AsyncTask<Integer, Void, Value[]> {
        private final String API_KEY = "xxxxx";
        private final String VARIABLE_ID = "xxxxx";

        @Override
        protected Value[] doInBackground(Integer... params){
            ApiClient apiClient = new ApiClient(API_KEY);
            Variable batteryLevel = apiClient.getVariable(VARIABLE_ID);
            Value[] variableValues = batteryLevel.getValues();

            return variableValues;
        }

        @Override
        protected void onPostExecute(Value[] variableValues) {
            // Update your views here
            TextView textView = (TextView) findViewById(dato);
            textView.setText(variableValues[0].toString());


        }



    }




}

You’re printing the textual representation of that Value instance in your TextView.

To show the numeric value that the instance holds, you should change this line:

textView.setText(variableValues[0].toString());

To this:

Double variableValue = variableValues[0].getValue();
textView.setText(String.valueOf(variableValue));
1 Like

great works perfectly

Great! We’re here to help you.