Hi,
I want to display the speed (example 89.0) value in my android textview i tried this way below but i don’t getting any output please help me to get my first value.
public class MainActivity extends AppCompatActivity
{
private final String API_KEY = "";
private final String VARIABLE_ID = "";
private TextView mSpeed;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSpeed = (TextView) findViewById(R.id.speed);
}
public void callAsynchronousTask() {
final Handler handler = new Handler();
Timer timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
try {
GetApiUbidots GetApiUbidots = new GetApiUbidots ();
GetApiUbidots.execute();
} catch (Exception e) {
android.util.Log.i("Error", "Error");
// TODO Auto-generated catch block
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, 2000);
}
public class ApiUbidots extends AsyncTask<String, Void, Void> {
private final String API_KEY = "";
private final String VARIABLE_ID = "";
@Override
protected Void doInBackground(Integer... params) {
ApiClient apiClient = new ApiClient(API_KEY);
mspeed = apiClient.getVariable(VARIABLE_ID);
return String.valueOf(mspeed);
}
protected void onPostExecute(String variableValues) {
// Update your views here
mSpeed.setText(Double.toString(Double.parseDouble(variableValues)));
}