class TestAsync extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
v.findViewById(R.id.loadinglayout).setVisibility(View.VISIBLE);
v.findViewById(R.id.wholecontentlayout).setVisibility(View.INVISIBLE);
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
callAPI();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
v.findViewById(R.id.loadinglayout).setVisibility(View.INVISIBLE);
v.findViewById(R.id.wholecontentlayout).setVisibility(View.VISIBLE);
}
}
public void callAPI ()
{
RequestInterface requestInterface = new RequestImplementation();
requestInterface.setUrl("https://api.myjson.com/bins/vl9pp");
ConnectionExecutor connectionExecutor = new
ConnectionImplementation();
ResponseInterface temp = null;
try {
temp = connectionExecutor.executeConnection(requestInterface);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
rangeText.setText(temp.getPayload());
}
Call API function will call a method of another class where HttpConnection is done.
If the function is directly called from onViewCreated()
in fragment then it works. If I call it from another async task it returns nothing.
I am actually trying to show a progress bar when the callApi function is called.