0

I'm working on a project that can get data from the cloud server, I'm using ubidots as my cloud server. Now I am trying to set the values I got from server to display on textView, but I cannot set it. I need to find a way where the textView have to be changed whenever the data variable changes. I don't know what do to on onPostExecute.

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

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

        return variableValues;
    }
@Override
    protected void onPostExecute(Value[] variableValues) {
        // Update your views here

     }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
EngrTayo
  • 11
  • 3
  • 1
    Also, I know this question is old, but please do not [repost your questions](http://stackoverflow.com/questions/34248468/how-to-update-a-textview-from-within-onpostexecute) – OneCricketeer Oct 06 '16 at 03:26

1 Answers1

0

If you want show last value from ubidots to textview. You can try to set Textview to be mgasDetector

@Override
    protected void onPostExecute(Value[] variableValues) {
        // Update your views here
String gas = Double.toString(variableValues[0].getValue());
            mgasDetector.setText(gas);

     }

may be it can help you

redim
  • 25
  • 1
  • 6
  • This assumes the views are accessible from within the AsyncTask – OneCricketeer Oct 06 '16 at 03:10
  • @cricket_007 yes it is. maybe you have another solution – redim Oct 06 '16 at 03:17
  • Flagged as a duplicate above. Besides, this question is almost a year old – OneCricketeer Oct 06 '16 at 03:22
  • Also, please [don't post identical answers to multiple questions](https://meta.stackexchange.com/q/104227). Post one good answer, then vote/flag to close the other questions as duplicates. If the question is not a duplicate, *tailor your answers to the question*. – OneCricketeer Oct 06 '16 at 03:23
  • sorry i didn't notice for duplicate. Recently i have the same problem. @cricket_007 would u help me for http://stackoverflow.com/questions/39867841/asynctask-for-update-button – redim Oct 06 '16 at 03:29