Here is my code where i want to update 4 textview but all 4 updating with same value as i don’t know how we can return multiple variable value from the AsyncTask in doInBackground so to use it in onPostExecute to update multiple TextView. i have attached the output where 4 time 31.00 value from ubidots service is fetched & displayed in 4 Android textview
Kindly help me to solve this issue.
public class MainActivity extends Activity {
TextView mspeed, mhacount,mtotaldis,mhbcount ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mspeed = (TextView) findViewById(R.id.speed);
mhacount = (TextView) findViewById(R.id.hacount);
mtotaldis = (TextView) findViewById(R.id.hbcount);
mhbcount = (TextView) findViewById(R.id.totaldis);
new ApiUbidots().execute(15);
}
public class ApiUbidots extends AsyncTask<Integer, Void, Value[]> {
private final String API_KEY = "A1E-xxxxxxxxxxxxxxxx";
private final String VARIABLE_ID = "xxxxxxxxxxxxxxxx";
private final String VARIABLE_ID_1 = "xxxxxxxxxxxxxxxx";
private final String VARIABLE_ID_2 = "xxxxxxxxxxxxxxxx";
private final String VARIABLE_ID_3 = "xxxxxxxxxxxxxxxx";
@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
Double variableValue = variableValues[0].getValue();
mspeed.setText(String.valueOf(variableValue));
mhacount.setText(String.valueOf(variableValue));
mtotaldis.setText(String.valueOf(variableValue));
mhbcount.setText(String.valueOf(variableValue));
}
}